Try to test settings added in the service.

This commit is contained in:
Marin Jankovski 2015-02-12 13:02:58 -08:00
parent d899bc914f
commit 1a89db5ffb
2 changed files with 24 additions and 1 deletions

View file

@ -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

View file

@ -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