summaryrefslogtreecommitdiff
path: root/lib/banzai
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-06-28 17:50:17 +0200
committerYorick Peterse <yorickpeterse@gmail.com>2016-06-30 11:52:44 +0200
commita4ce2d126d969722af7152c4be2c8a6dde3104b5 (patch)
treed65701227d80752d4a6cd583af9a082866bbc2ab /lib/banzai
parentbef4294c58e0bbadc01f633fc8bea514801de7ae (diff)
downloadgitlab-ce-a4ce2d126d969722af7152c4be2c8a6dde3104b5.tar.gz
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
Diffstat (limited to 'lib/banzai')
-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
3 files changed, 30 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