Commit 103a1bb0 authored by Marin Jankovski's avatar Marin Jankovski

Use service settings instead of config file settings to present issues.

parent 737f6516
...@@ -16,7 +16,7 @@ module IssuesHelper ...@@ -16,7 +16,7 @@ module IssuesHelper
def url_for_project_issues(project = @project) def url_for_project_issues(project = @project)
return '' if project.nil? return '' if project.nil?
if project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !project.external_issues_tracker_enabled?
project_issues_path(project) project_issues_path(project)
else else
url = Gitlab.config.issues_tracker[project.issues_tracker]['project_url'] url = Gitlab.config.issues_tracker[project.issues_tracker]['project_url']
...@@ -28,7 +28,7 @@ module IssuesHelper ...@@ -28,7 +28,7 @@ module IssuesHelper
def url_for_new_issue(project = @project) def url_for_new_issue(project = @project)
return '' if project.nil? return '' if project.nil?
if project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !project.external_issues_tracker_enabled?
url = new_project_issue_path project_id: project url = new_project_issue_path project_id: project
else else
issues_tracker = Gitlab.config.issues_tracker[project.issues_tracker] issues_tracker = Gitlab.config.issues_tracker[project.issues_tracker]
...@@ -41,7 +41,7 @@ module IssuesHelper ...@@ -41,7 +41,7 @@ module IssuesHelper
def url_for_issue(issue_iid, project = @project) def url_for_issue(issue_iid, project = @project)
return '' if project.nil? return '' if project.nil?
if project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !project.external_issues_tracker_enabled?
url = project_issue_url project_id: project, id: issue_iid url = project_issue_url project_id: project, id: issue_iid
else else
url = Gitlab.config.issues_tracker[project.issues_tracker]['issues_url'] url = Gitlab.config.issues_tracker[project.issues_tracker]['issues_url']
...@@ -77,11 +77,6 @@ module IssuesHelper ...@@ -77,11 +77,6 @@ module IssuesHelper
ts.html_safe ts.html_safe
end end
# Checks if issues_tracker setting exists in gitlab.yml
def external_issues_tracker_enabled?
Gitlab.config.issues_tracker && Gitlab.config.issues_tracker.values.any?
end
def bulk_update_milestone_options def bulk_update_milestone_options
options_for_select(['None (backlog)']) + options_for_select(['None (backlog)']) +
options_from_collection_for_select(project_active_milestones, 'id', options_from_collection_for_select(project_active_milestones, 'id',
......
...@@ -309,6 +309,18 @@ class Project < ActiveRecord::Base ...@@ -309,6 +309,18 @@ class Project < ActiveRecord::Base
self.issues_tracker == Project.issues_tracker.default_value self.issues_tracker == Project.issues_tracker.default_value
end end
def external_issues_tracker_enabled?
external_issues_trackers.any?
end
def external_issues_trackers
services.select { |service| service.category == :issue_tracker }
end
def external_issue_tracker
@external_issues_tracker ||= external_issues_trackers.select(&:activated?).first
end
def can_have_issues_tracker_id? def can_have_issues_tracker_id?
self.issues_enabled && !self.used_default_issues_tracker? self.issues_enabled && !self.used_default_issues_tracker?
end end
......
class IssueTrackerService < Service class IssueTrackerService < Service
def category
:issue_tracker
end
def project_url def project_url
# implement inside child # implement inside child
end end
......
...@@ -48,9 +48,9 @@ class RedmineService < IssueTrackerService ...@@ -48,9 +48,9 @@ class RedmineService < IssueTrackerService
end end
def set_project_url def set_project_url
id = self.project.issue_tracker_id id = self.project.issues_tracker_id
if id if id
issues_tracker['project_url'].gsub(":issue_tracker_id", id) issues_tracker['project_url'].gsub(":issues_tracker_id", id)
else else
issues_tracker['project_url'] issues_tracker['project_url']
end end
......
...@@ -208,7 +208,7 @@ module Gitlab ...@@ -208,7 +208,7 @@ module Gitlab
end end
def reference_issue(identifier, project = @project, prefix_text = nil) def reference_issue(identifier, project = @project, prefix_text = nil)
if project.used_default_issues_tracker? || !external_issues_tracker_enabled? if project.used_default_issues_tracker? || !project.external_issues_tracker_enabled?
if project.issue_exists? identifier if project.issue_exists? identifier
url = url_for_issue(identifier, project) url = url_for_issue(identifier, project)
title = title_for_issue(identifier, project) title = title_for_issue(identifier, project)
...@@ -220,8 +220,7 @@ module Gitlab ...@@ -220,8 +220,7 @@ module Gitlab
link_to("#{prefix_text}##{identifier}", url, options) link_to("#{prefix_text}##{identifier}", url, options)
end end
else else
config = Gitlab.config external_issue_tracker = project.external_issue_tracker
external_issue_tracker = config.issues_tracker[project.issues_tracker]
if external_issue_tracker.present? if external_issue_tracker.present?
reference_external_issue(identifier, external_issue_tracker, project, reference_external_issue(identifier, external_issue_tracker, project,
prefix_text) prefix_text)
...@@ -270,7 +269,7 @@ module Gitlab ...@@ -270,7 +269,7 @@ module Gitlab
def reference_external_issue(identifier, issue_tracker, project = @project, def reference_external_issue(identifier, issue_tracker, project = @project,
prefix_text = nil) prefix_text = nil)
url = url_for_issue(identifier, project) url = url_for_issue(identifier, project)
title = issue_tracker['title'] title = issue_tracker.title
options = html_options.merge( options = html_options.merge(
title: "Issue in #{title}", title: "Issue in #{title}",
......
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