diff --git a/docs/SAPDshell b/docs/SAPDshell new file mode 100644 index 000000000..f2fb7938d --- /dev/null +++ b/docs/SAPDshell @@ -0,0 +1,19 @@ +SAPDshell +========= + +The SAP HANA Deployment shell (Dshell) is a cloud-hosted service provided by SAP for developers to deploy HTML and JavaScript sources to SAP HANA development edition. + +Integrating with GitHub will allow you to associate Git commits to specific HANA database. + + +Install Notes +------------- + +1. **DShell URL** - This is the URL of the DShell instance and port you are using +2. **User** - This is the user on your HANA instance. +3. **Password** - This is your Passowrd on the HANA instance. + +Need Help? +---------- + +Check out our [step by step instructions](http://scn.sap.com/docs/DOC-41137). diff --git a/lib/services/SAPDshell.rb b/lib/services/SAPDshell.rb new file mode 100644 index 000000000..e4724d265 --- /dev/null +++ b/lib/services/SAPDshell.rb @@ -0,0 +1,57 @@ +class Service::SAPDshell < Service::HttpPost + string :dshell_url, :user_id + password :password + + + url "http://dshell.saphana.com" + logo_url "http://www.sap.com/global/ui/images/global/sap-logo.png" + + # SAPDshell on GitHub is pinged for any bugs with the Hook code. + maintained_by :github => 'SAPDshell' + + # Support channels for user-level Hook problems (service failure, + # misconfigured + supported_by :web => 'http://scn.sap.com/community/developer-center/content', + :email => 'dshell@sap.com' + + + def receive_event + + # Check for settings + if required_config_value('dshell_url').to_s.empty? + raise_config_error "SAP Dshell URL not set" + end + if required_config_value('user_id').to_s.empty? + raise_config_error "User id not set" + end + if required_config_value('password').to_s.empty? + raise_config_error "Password not set" + end + + # Sets this basic auth info for every request. + http.basic_auth( required_config_value('user_id'), required_config_value('password')) + + http.headers['Content-Type'] = 'application/json' + + # Uses this URL as a prefix for every request. + http.url_prefix = "http://" + + + l_repository = payload['repository']['url'].to_s + l_dshell_url = required_config_value('dshell_url') + + l_call_url = "#{l_dshell_url}/?repo=#{l_repository}" + + res = deliver l_call_url + + + if res.status < 200 || res.status > 299 + raise_config_error "Failed with #{res.status}" + end + + rescue URI::InvalidURIError + raise_config_error "Invalid URL: #{l_call_url}" + + +end +end diff --git a/test/SAPDshell_test.rb b/test/SAPDshell_test.rb new file mode 100644 index 000000000..5fd2b40c0 --- /dev/null +++ b/test/SAPDshell_test.rb @@ -0,0 +1,25 @@ +require File.expand_path('../helper', __FILE__) + +class SAPDshellTest < Service::TestCase + def setup + @stubs = Faraday::Adapter::Test::Stubs.new + end + + def test_push + @stubs.post "/api/github/a" do |env| + assert_equal 'dshell.saphana.com', env[:url].host + data = Faraday::Utils.parse_query(env[:body]) + assert_equal payload.to_json, data['payload'] + [200, {}, ''] + end + + svc = service({'dshell_url' => 'dshell.saphana.com:30015', 'user_id' => 'system', 'password' => 'HANA2012' }, + payload) + svc.receive_push + + end + + def service(*args) + super Service::SAPDshell, *args + end +end