Skip to content

Commit

Permalink
Merge branch 'fix-external-issue-rendering' into 'master'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Robert Speicher committed Jun 30, 2016
2 parents f7b0561 + 4fca633 commit 6e82c0e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
14 changes: 9 additions & 5 deletions lib/banzai/filter/abstract_reference_filter.rb
Expand Up @@ -160,11 +160,7 @@ def object_link_filter(text, pattern, link_text: nil)
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]
Expand All @@ -183,6 +179,14 @@ def object_link_filter(text, pattern, link_text: nil)
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 = []

Expand Down
20 changes: 20 additions & 0 deletions lib/banzai/filter/issue_reference_filter.rb
Expand Up @@ -46,6 +46,26 @@ def issues_per_project
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
Expand Down
2 changes: 1 addition & 1 deletion lib/banzai/filter/reference_filter.rb
Expand Up @@ -29,7 +29,7 @@ class << self
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
Expand Down
13 changes: 13 additions & 0 deletions spec/lib/banzai/filter/issue_reference_filter_spec.rb
Expand Up @@ -199,6 +199,19 @@ def helper
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
Expand Down
2 changes: 2 additions & 0 deletions spec/services/git_push_service_spec.rb
Expand Up @@ -350,6 +350,8 @@
it "doesn't close issues when external issue tracker is in use" do
allow_any_instance_of(Project).to receive(:default_issues_tracker?).
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.
expect do
Expand Down

0 comments on commit 6e82c0e

Please sign in to comment.