2021-04-15 18:09:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Banzai
|
|
|
|
module Filter
|
|
|
|
module References
|
|
|
|
# HTML filter that replaces commit range references with links.
|
|
|
|
#
|
|
|
|
# This filter supports cross-project references.
|
|
|
|
class CommitRangeReferenceFilter < AbstractReferenceFilter
|
|
|
|
self.reference_type = :commit_range
|
2021-04-22 12:09:49 +00:00
|
|
|
self.object_class = CommitRange
|
2021-04-15 18:09:01 +00:00
|
|
|
|
2021-04-22 12:09:49 +00:00
|
|
|
def references_in(text, pattern = object_reference_pattern)
|
2021-04-15 18:09:01 +00:00
|
|
|
text.gsub(pattern) do |match|
|
|
|
|
yield match, $~[:commit_range], $~[:project], $~[:namespace], $~
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(*args)
|
|
|
|
super
|
|
|
|
|
|
|
|
@commit_map = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
def find_object(project, id)
|
|
|
|
return unless project.is_a?(Project)
|
|
|
|
|
|
|
|
range = CommitRange.new(id, project)
|
|
|
|
|
|
|
|
range.valid_commits? ? range : nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def url_for_object(range, project)
|
|
|
|
h = Gitlab::Routing.url_helpers
|
|
|
|
h.project_compare_url(project,
|
|
|
|
range.to_param.merge(only_path: context[:only_path]))
|
|
|
|
end
|
|
|
|
|
|
|
|
def object_link_title(range, matches)
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|