Handle external issues in IssueReferenceFilter
IssueReferenceFilter will end up processing internal issue references when a project uses an external issues tracker while still using internal issue references (in the form of `#\d+`). This commit ensures that these links are rendered as external issue links, regardless of whether the project one currently views uses an internal or external issues tracker. Fixes gitlab-org/gitlab-ce#19036, gitlab-com/performance#16
This commit is contained in:
parent
bef4294c58
commit
a4ce2d126d
|
@ -160,11 +160,7 @@ module Banzai
|
|||
title = object_link_title(object)
|
||||
klass = reference_class(object_sym)
|
||||
|
||||
data = data_attribute(
|
||||
original: link_text || match,
|
||||
project: project.id,
|
||||
object_sym => object.id
|
||||
)
|
||||
data = data_attributes_for(link_text || match, project, object)
|
||||
|
||||
if matches.names.include?("url") && matches[:url]
|
||||
url = matches[:url]
|
||||
|
@ -183,6 +179,14 @@ module Banzai
|
|||
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)
|
||||
extras = []
|
||||
|
||||
|
|
|
@ -46,6 +46,26 @@ module Banzai
|
|||
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)
|
||||
super(paths).includes(:gitlab_issue_tracker_service)
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module Banzai
|
|||
def data_attribute(attributes = {})
|
||||
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.map { |key, value| %Q(data-#{key.to_s.dasherize}="#{escape_once(value)}") }.join(" ")
|
||||
end
|
||||
|
|
|
@ -199,6 +199,19 @@ describe Banzai::Filter::IssueReferenceFilter, lib: true do
|
|||
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
|
||||
context 'using an internal issue tracker' do
|
||||
it 'returns a Hash containing the issues per project' do
|
||||
|
|
Loading…
Reference in New Issue