PageRenderTime 40ms CodeModel.GetById 30ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/banzai/filter/merge_request_reference_filter.rb

https://gitlab.com/vicvega/gitlab-ce
Ruby | 41 lines | 31 code | 6 blank | 4 comment | 1 complexity | 1bed0c8269d63a5a856171418a868607 MD5 | raw file
 1module Banzai
 2  module Filter
 3    # HTML filter that replaces merge request references with links. References
 4    # to merge requests that do not exist are ignored.
 5    #
 6    # This filter supports cross-project references.
 7    class MergeRequestReferenceFilter < AbstractReferenceFilter
 8      self.reference_type = :merge_request
 9
10      def self.object_class
11        MergeRequest
12      end
13
14      def find_object(project, id)
15        project.merge_requests.find_by(iid: id)
16      end
17
18      def url_for_object(mr, project)
19        h = Gitlab::Routing.url_helpers
20        h.namespace_project_merge_request_url(project.namespace, project, mr,
21                                            only_path: context[:only_path])
22      end
23
24      def object_link_text_extras(object, matches)
25        extras = super
26
27        path = matches[:path] if matches.names.include?("path")
28        case path
29        when '/diffs'
30          extras.unshift "diffs"
31        when '/commits'
32          extras.unshift "commits"
33        when '/builds'
34          extras.unshift "builds"
35        end
36
37        extras
38      end
39    end
40  end
41end