Read about our upcoming Code of Conduct on this issue

commit_range_reference_filter.rb 1.05 KB
Newer Older
1
2
module Banzai
  module Filter
3
    # HTML filter that replaces commit range references with links.
Robert Speicher's avatar
Robert Speicher committed
4
5
    #
    # This filter supports cross-project references.
6
    class CommitRangeReferenceFilter < AbstractReferenceFilter
7
8
      self.reference_type = :commit_range

9
10
11
      def self.object_class
        CommitRange
      end
Robert Speicher's avatar
Robert Speicher committed
12

13
14
      def self.references_in(text, pattern = CommitRange.reference_pattern)
        text.gsub(pattern) do |match|
15
          yield match, $~[:commit_range], $~[:project], $~[:namespace], $~
Robert Speicher's avatar
Robert Speicher committed
16
17
18
        end
      end

19
20
21
22
23
24
      def initialize(*args)
        super

        @commit_map = {}
      end

25
      def find_object(project, id)
26
        range = CommitRange.new(id, project)
Robert Speicher's avatar
Robert Speicher committed
27

28
29
        range.valid_commits? ? range : nil
      end
Robert Speicher's avatar
Robert Speicher committed
30

31
      def url_for_object(range, project)
32
        h = Gitlab::Routing.url_helpers
Robert Speicher's avatar
Robert Speicher committed
33
        h.namespace_project_compare_url(project.namespace, project,
34
                                        range.to_param.merge(only_path: context[:only_path]))
Robert Speicher's avatar
Robert Speicher committed
35
      end
36
37

      def object_link_title(range)
38
        nil
39
      end
Robert Speicher's avatar
Robert Speicher committed
40
41
42
    end
  end
end