Commit 0027c2dd authored by Robert Speicher's avatar Robert Speicher

Add Project#get_issue

parent 466bec7c
...@@ -329,12 +329,16 @@ class Project < ActiveRecord::Base ...@@ -329,12 +329,16 @@ class Project < ActiveRecord::Base
self.id self.id
end end
def issue_exists?(issue_id) def get_issue(issue_id)
if default_issues_tracker? if default_issues_tracker?
self.issues.where(iid: issue_id).first.present? issues.find_by(iid: issue_id)
else else
true ExternalIssue.new(issue_id, self)
end
end end
def issue_exists?(issue_id)
get_issue(issue_id).present?
end end
def default_issue_tracker def default_issue_tracker
...@@ -350,11 +354,7 @@ class Project < ActiveRecord::Base ...@@ -350,11 +354,7 @@ class Project < ActiveRecord::Base
end end
def default_issues_tracker? def default_issues_tracker?
if external_issue_tracker external_issue_tracker.blank?
false
else
true
end
end end
def external_issues_trackers def external_issues_trackers
......
...@@ -44,21 +44,20 @@ module Gitlab ...@@ -44,21 +44,20 @@ module Gitlab
# Returns a String with `#123` references replaced with links. All links # Returns a String with `#123` references replaced with links. All links
# have `gfm` and `gfm-issue` class names attached for styling. # have `gfm` and `gfm-issue` class names attached for styling.
def issue_link_filter(text) def issue_link_filter(text)
self.class.references_in(text) do |match, issue, project_ref| self.class.references_in(text) do |match, id, project_ref|
project = self.project_from_ref(project_ref) project = self.project_from_ref(project_ref)
if project && project.issue_exists?(issue) if project && issue = project.get_issue(id)
# FIXME (rspeicher): Law of Demeter push_result(:issue, issue)
push_result(:issue, project.issues.where(iid: issue).first)
url = url_for_issue(issue, project, only_path: context[:only_path]) url = url_for_issue(id, project, only_path: context[:only_path])
title = escape_once("Issue: #{title_for_issue(issue, project)}") title = escape_once("Issue: #{title_for_issue(id, project)}")
klass = reference_class(:issue) klass = reference_class(:issue)
%(<a href="#{url}" %(<a href="#{url}"
title="#{title}" title="#{title}"
class="#{klass}">#{project_ref}##{issue}</a>) class="#{klass}">#{project_ref}##{id}</a>)
else else
match match
end end
......
...@@ -27,7 +27,7 @@ module Gitlab::Markdown ...@@ -27,7 +27,7 @@ module Gitlab::Markdown
let(:reference) { "##{issue.iid}" } let(:reference) { "##{issue.iid}" }
it 'ignores valid references when using non-default tracker' do it 'ignores valid references when using non-default tracker' do
expect(project).to receive(:issue_exists?).with(issue.iid).and_return(false) expect(project).to receive(:get_issue).with(issue.iid).and_return(nil)
exp = act = "Issue ##{issue.iid}" exp = act = "Issue ##{issue.iid}"
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
...@@ -48,7 +48,7 @@ module Gitlab::Markdown ...@@ -48,7 +48,7 @@ module Gitlab::Markdown
it 'ignores invalid issue IDs' do it 'ignores invalid issue IDs' do
exp = act = "Fixed ##{issue.iid + 1}" exp = act = "Fixed ##{issue.iid + 1}"
expect(project).to receive(:issue_exists?).with(issue.iid + 1) expect(project).to receive(:get_issue).with(issue.iid + 1).and_return(nil)
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
end end
...@@ -98,8 +98,8 @@ module Gitlab::Markdown ...@@ -98,8 +98,8 @@ module Gitlab::Markdown
before { allow_cross_reference! } before { allow_cross_reference! }
it 'ignores valid references when cross-reference project uses external tracker' do it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(Project).to receive(:issue_exists?). expect_any_instance_of(Project).to receive(:get_issue).
with(issue.iid).and_return(false) with(issue.iid).and_return(nil)
exp = act = "Issue ##{issue.iid}" exp = act = "Issue ##{issue.iid}"
expect(filter(act).to_html).to eq exp expect(filter(act).to_html).to eq exp
......
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