diff options
author | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-13 17:59:03 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@gitlab.com> | 2015-02-13 17:59:03 +0000 |
commit | c676856f1bf665695e5ea1eb365f9436e39f8a34 (patch) | |
tree | b5abe6b6c719389e1adb53b488073e9e5ac58ec0 | |
parent | b8cc501c3e93d225b826f646a673a97dd0baea9f (diff) | |
parent | 8a37435738423853654ec622d59fbb2048ad7a1e (diff) | |
download | gitlab-ce-c676856f1bf665695e5ea1eb365f9436e39f8a34.tar.gz |
Merge branch 'test_settings' into 'master'
Test settings for issue tracker service
This adds minimum logging and response when using "test settings" button when the service is enabled.
See merge request !1506
-rw-r--r-- | app/controllers/projects/services_controller.rb | 2 | ||||
-rw-r--r-- | app/models/project_services/issue_tracker_service.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/app/controllers/projects/services_controller.rb b/app/controllers/projects/services_controller.rb index b3110eacc18..2b3e70f7bdb 100644 --- a/app/controllers/projects/services_controller.rb +++ b/app/controllers/projects/services_controller.rb @@ -29,7 +29,7 @@ class Projects::ServicesController < Projects::ApplicationController if @service.execute(data) message = { notice: 'We sent a request to the provided URL' } else - message = { alert: 'We tried to send a request to the provided URL but error occured' } + message = { alert: 'We tried to send a request to the provided URL but an error occured' } end redirect_to :back, message diff --git a/app/models/project_services/issue_tracker_service.rb b/app/models/project_services/issue_tracker_service.rb index 51b2fb3dcc7..c991a34ecdb 100644 --- a/app/models/project_services/issue_tracker_service.rb +++ b/app/models/project_services/issue_tracker_service.rb @@ -65,6 +65,29 @@ class IssueTrackerService < Service end end + def execute(data) + message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again." + result = false + + begin + url = URI.parse(self.project_url) + + if url.host && url.port + http = Net::HTTP.start(url.host, url.port, { open_timeout: 5, read_timeout: 5 }) + response = http.head("/") + + if response + message = "#{self.type} received response #{response.code} when attempting to connect to #{self.project_url}" + result = true + end + end + rescue Timeout::Error, SocketError, Errno::ECONNRESET, Errno::ECONNREFUSED => error + message = "#{self.type} had an error when trying to connect to #{self.project_url}: #{error.message}" + end + Rails.logger.info(message) + result + end + private def enabled_in_gitlab_config |