summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2016-06-30 17:46:20 +0000
committerRobert Speicher <robert@gitlab.com>2016-06-30 17:46:20 +0000
commit6e82c0e06ea25d6d0871037fb09301698ca972bd (patch)
tree144da3938466c90af68cdc8cafeec4f14485a4b0
parentf7b056167a3dd79dde7b7fdd87209b478975c546 (diff)
parent4fca633a317eb065145d3cc687f62eabcb8e8af2 (diff)
downloadgitlab-ce-6e82c0e06ea25d6d0871037fb09301698ca972bd.tar.gz
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
-rw-r--r--lib/banzai/filter/abstract_reference_filter.rb14
-rw-r--r--lib/banzai/filter/issue_reference_filter.rb20
-rw-r--r--lib/banzai/filter/reference_filter.rb2
-rw-r--r--spec/lib/banzai/filter/issue_reference_filter_spec.rb13
-rw-r--r--spec/services/git_push_service_spec.rb2
5 files changed, 45 insertions, 6 deletions
diff --git a/lib/banzai/filter/abstract_reference_filter.rb b/lib/banzai/filter/abstract_reference_filter.rb
index 81d66271136..d77a5e3ff09 100644
--- a/lib/banzai/filter/abstract_reference_filter.rb
+++ b/lib/banzai/filter/abstract_reference_filter.rb
@@ -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 = []
diff --git a/lib/banzai/filter/issue_reference_filter.rb b/lib/banzai/filter/issue_reference_filter.rb
index 5351272f42d..4042e9a4c25 100644
--- a/lib/banzai/filter/issue_reference_filter.rb
+++ b/lib/banzai/filter/issue_reference_filter.rb
@@ -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
diff --git a/lib/banzai/filter/reference_filter.rb b/lib/banzai/filter/reference_filter.rb
index 2d6f34c9cd8..bf058241cda 100644
--- a/lib/banzai/filter/reference_filter.rb
+++ b/lib/banzai/filter/reference_filter.rb
@@ -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
diff --git a/spec/lib/banzai/filter/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/issue_reference_filter_spec.rb
index 8d6ce114aa9..a005b4990e7 100644
--- a/spec/lib/banzai/filter/issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/issue_reference_filter_spec.rb
@@ -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
diff --git a/spec/services/git_push_service_spec.rb b/spec/services/git_push_service_spec.rb
index 1ceb7c3e6ff..48d374883d7 100644
--- a/spec/services/git_push_service_spec.rb
+++ b/spec/services/git_push_service_spec.rb
@@ -350,6 +350,8 @@ describe GitPushService, services: true do
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