Commit 6e82c0e0 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'fix-external-issue-rendering' into 'master'

Handle external issues in IssueReferenceFilter

Rendering issue references such as `#1` was broken for projects using an external issues tracker.

See gitlab-org/gitlab-ce#19036

See merge request !4988
parents f7b05616 4fca633a
...@@ -160,11 +160,7 @@ module Banzai ...@@ -160,11 +160,7 @@ module Banzai
title = object_link_title(object) title = object_link_title(object)
klass = reference_class(object_sym) klass = reference_class(object_sym)
data = data_attribute( data = data_attributes_for(link_text || match, project, object)
original: link_text || match,
project: project.id,
object_sym => object.id
)
if matches.names.include?("url") && matches[:url] if matches.names.include?("url") && matches[:url]
url = matches[:url] url = matches[:url]
...@@ -183,6 +179,14 @@ module Banzai ...@@ -183,6 +179,14 @@ module Banzai
end end
end end
def data_attributes_for(text, project, object)
data_attribute(
original: text,
project: project.id,
object_sym => object.id
)
end
def object_link_text_extras(object, matches) def object_link_text_extras(object, matches)
extras = [] extras = []
......
...@@ -46,6 +46,26 @@ module Banzai ...@@ -46,6 +46,26 @@ module Banzai
end end
end end
def object_link_title(object)
if object.is_a?(ExternalIssue)
"Issue in #{object.project.external_issue_tracker.title}"
else
super
end
end
def data_attributes_for(text, project, object)
if object.is_a?(ExternalIssue)
data_attribute(
project: project.id,
external_issue: object.id,
reference_type: ExternalIssueReferenceFilter.reference_type
)
else
super
end
end
def find_projects_for_paths(paths) def find_projects_for_paths(paths)
super(paths).includes(:gitlab_issue_tracker_service) super(paths).includes(:gitlab_issue_tracker_service)
end end
......
...@@ -29,7 +29,7 @@ module Banzai ...@@ -29,7 +29,7 @@ module Banzai
def data_attribute(attributes = {}) def data_attribute(attributes = {})
attributes = attributes.reject { |_, v| v.nil? } attributes = attributes.reject { |_, v| v.nil? }
attributes[:reference_type] = self.class.reference_type attributes[:reference_type] ||= self.class.reference_type
attributes.delete(:original) if context[:no_original_data] attributes.delete(:original) if context[:no_original_data]
attributes.map { |key, value| %Q(data-#{key.to_s.dasherize}="#{escape_once(value)}") }.join(" ") attributes.map { |key, value| %Q(data-#{key.to_s.dasherize}="#{escape_once(value)}") }.join(" ")
end end
......
...@@ -199,6 +199,19 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do ...@@ -199,6 +199,19 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
end end
end end
context 'referencing external issues' do
let(:project) { create(:redmine_project) }
it 'renders internal issue IDs as external issue links' do
doc = reference_filter('#1')
link = doc.css('a').first
expect(link.attr('data-reference-type')).to eq('external_issue')
expect(link.attr('title')).to eq('Issue in Redmine')
expect(link.attr('data-external-issue')).to eq('1')
end
end
describe '#issues_per_Project' do describe '#issues_per_Project' do
context 'using an internal issue tracker' do context 'using an internal issue tracker' do
it 'returns a Hash containing the issues per project' do it 'returns a Hash containing the issues per project' do
......
...@@ -350,6 +350,8 @@ describe GitPushService, services: true do ...@@ -350,6 +350,8 @@ describe GitPushService, services: true do
it "doesn't close issues when external issue tracker is in use" do it "doesn't close issues when external issue tracker is in use" do
allow_any_instance_of(Project).to receive(:default_issues_tracker?). allow_any_instance_of(Project).to receive(:default_issues_tracker?).
and_return(false) and_return(false)
external_issue_tracker = double(title: 'My Tracker', issue_path: issue.iid)
allow_any_instance_of(Project).to receive(:external_issue_tracker).and_return(external_issue_tracker)
# The push still shouldn't create cross-reference notes. # The push still shouldn't create cross-reference notes.
expect do expect do
......
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