Commit c676856f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

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
parents b8cc501c 8a374357
...@@ -29,7 +29,7 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -29,7 +29,7 @@ class Projects::ServicesController < Projects::ApplicationController
if @service.execute(data) if @service.execute(data)
message = { notice: 'We sent a request to the provided URL' } message = { notice: 'We sent a request to the provided URL' }
else 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 end
redirect_to :back, message redirect_to :back, message
......
...@@ -65,6 +65,29 @@ class IssueTrackerService < Service ...@@ -65,6 +65,29 @@ class IssueTrackerService < Service
end end
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 private
def enabled_in_gitlab_config def enabled_in_gitlab_config
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment