summaryrefslogtreecommitdiff
path: root/lib/gitlab/markdown/merge_request_reference_filter.rb
blob: de71fc76a9b3e8f07e108242d6b4b5464ef7a39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'gitlab/markdown'

module Gitlab
  module Markdown
    # HTML filter that replaces merge request references with links. References
    # to merge requests that do not exist are ignored.
    #
    # This filter supports cross-project references.
    class MergeRequestReferenceFilter < AbstractReferenceFilter
      def self.object_class
        MergeRequest
      end

      def find_object(project, id)
        project.merge_requests.find_by(iid: id)
      end

      def url_for_object(mr, project)
        h = Gitlab::Application.routes.url_helpers
        h.namespace_project_merge_request_url(project.namespace, project, mr,
                                            only_path: context[:only_path])
      end

      def object_link_text_extras(object, matches)
        extras = super

        if matches.names.include?("path") && matches[:path] && matches[:path] == '/diffs'
          extras.unshift "diffs"
        end

        extras
      end
    end
  end
end