2015-02-02 13:24:40 -05:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# type :string(255)
|
|
|
|
# title :string(255)
|
|
|
|
# project_id :integer not null
|
|
|
|
# created_at :datetime
|
|
|
|
# updated_at :datetime
|
|
|
|
# active :boolean default(FALSE), not null
|
|
|
|
# properties :text
|
|
|
|
#
|
|
|
|
|
2015-01-20 19:46:27 -05:00
|
|
|
class IssueTrackerService < Service
|
|
|
|
|
2015-01-27 01:08:27 -05:00
|
|
|
validates :project_url, :issues_url, :new_issue_url, presence: true, if: :activated?
|
|
|
|
|
2015-01-23 13:28:38 -05:00
|
|
|
def category
|
|
|
|
:issue_tracker
|
|
|
|
end
|
|
|
|
|
2015-01-28 12:28:17 -05:00
|
|
|
def default?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2015-01-20 19:46:27 -05:00
|
|
|
def project_url
|
|
|
|
# implement inside child
|
|
|
|
end
|
|
|
|
|
|
|
|
def issues_url
|
|
|
|
# implement inside child
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_issue_url
|
|
|
|
# implement inside child
|
|
|
|
end
|
2015-01-26 19:24:11 -05:00
|
|
|
|
2015-01-28 16:19:32 -05:00
|
|
|
def issue_url(iid)
|
|
|
|
self.issues_url.gsub(':id', iid.to_s)
|
|
|
|
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'],
|
|
|
|
project_url: set_project_url,
|
|
|
|
issues_url: issues_tracker['issues_url'],
|
|
|
|
new_issue_url: issues_tracker['new_issue_url']
|
|
|
|
}
|
2015-01-27 01:08:27 -05:00
|
|
|
else
|
|
|
|
self.properties = {}
|
2015-01-26 19:24:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
def set_project_url
|
|
|
|
id = self.project.issues_tracker_id
|
|
|
|
|
|
|
|
if id
|
|
|
|
issues_tracker['project_url'].gsub(":issues_tracker_id", id)
|
|
|
|
else
|
|
|
|
issues_tracker['project_url']
|
|
|
|
end
|
|
|
|
end
|
2015-01-20 19:46:27 -05:00
|
|
|
end
|