2015-01-20 19:46:27 -05:00
|
|
|
class IssueTrackerService < Service
|
2016-04-21 11:13:14 -04:00
|
|
|
validates :project_url, :issues_url, :new_issue_url, presence: true, url: true, if: :activated?
|
2015-01-27 01:08:27 -05:00
|
|
|
|
2016-01-19 07:48:07 -05:00
|
|
|
default_value_for :category, 'issue_tracker'
|
2015-01-23 13:28:38 -05:00
|
|
|
|
2015-01-28 12:28:17 -05:00
|
|
|
def default?
|
2016-01-19 07:48:07 -05:00
|
|
|
default
|
2015-01-28 12:28:17 -05:00
|
|
|
end
|
|
|
|
|
2015-01-28 16:19:32 -05:00
|
|
|
def issue_url(iid)
|
|
|
|
self.issues_url.gsub(':id', iid.to_s)
|
|
|
|
end
|
|
|
|
|
2015-03-25 05:03:55 -04:00
|
|
|
def project_path
|
|
|
|
project_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_issue_path
|
|
|
|
new_issue_url
|
|
|
|
end
|
|
|
|
|
|
|
|
def issue_path(iid)
|
|
|
|
issue_url(iid)
|
|
|
|
end
|
|
|
|
|
2015-01-26 19:24:11 -05:00
|
|
|
def fields
|
|
|
|
[
|
|
|
|
{ type: 'text', name: 'description', placeholder: description },
|
|
|
|
{ type: 'text', name: 'project_url', placeholder: 'Project url' },
|
2015-02-02 23:36:54 -05:00
|
|
|
{ type: 'text', name: 'issues_url', placeholder: 'Issue url' },
|
|
|
|
{ type: 'text', name: 'new_issue_url', placeholder: 'New Issue url' }
|
2015-01-26 19:24:11 -05:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize_properties
|
|
|
|
if properties.nil?
|
|
|
|
if enabled_in_gitlab_config
|
|
|
|
self.properties = {
|
|
|
|
title: issues_tracker['title'],
|
2016-06-10 15:53:20 -04:00
|
|
|
project_url: issues_tracker['project_url'],
|
|
|
|
issues_url: issues_tracker['issues_url'],
|
|
|
|
new_issue_url: issues_tracker['new_issue_url']
|
2015-01-26 19:24:11 -05:00
|
|
|
}
|
2015-01-27 01:08:27 -05:00
|
|
|
else
|
|
|
|
self.properties = {}
|
2015-01-26 19:24:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-28 11:33:18 -05:00
|
|
|
def supported_events
|
|
|
|
%w(push)
|
|
|
|
end
|
|
|
|
|
2015-02-12 16:02:58 -05:00
|
|
|
def execute(data)
|
2015-02-28 11:33:18 -05:00
|
|
|
return unless supported_events.include?(data[:object_kind])
|
2015-02-19 00:02:57 -05:00
|
|
|
|
2015-02-12 16:02:58 -05:00
|
|
|
message = "#{self.type} was unable to reach #{self.project_url}. Check the url and try again."
|
|
|
|
result = false
|
|
|
|
|
|
|
|
begin
|
2015-06-04 15:08:35 -04:00
|
|
|
response = HTTParty.head(self.project_url, verify: true)
|
2015-02-12 16:02:58 -05:00
|
|
|
|
2015-06-04 15:08:35 -04:00
|
|
|
if response
|
|
|
|
message = "#{self.type} received response #{response.code} when attempting to connect to #{self.project_url}"
|
|
|
|
result = true
|
2015-02-12 16:02:58 -05:00
|
|
|
end
|
2015-06-04 15:08:35 -04:00
|
|
|
rescue HTTParty::Error, Timeout::Error, SocketError, Errno::ECONNRESET, Errno::ECONNREFUSED => error
|
2015-02-12 16:02:58 -05:00
|
|
|
message = "#{self.type} had an error when trying to connect to #{self.project_url}: #{error.message}"
|
|
|
|
end
|
|
|
|
Rails.logger.info(message)
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
2015-01-26 19:24:11 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def enabled_in_gitlab_config
|
|
|
|
Gitlab.config.issues_tracker &&
|
|
|
|
Gitlab.config.issues_tracker.values.any? &&
|
|
|
|
issues_tracker
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_tracker
|
|
|
|
Gitlab.config.issues_tracker[to_param]
|
|
|
|
end
|
2015-01-20 19:46:27 -05:00
|
|
|
end
|