Class: Banzai::Filter::MergeRequestReferenceFilter

Inherits:
AbstractReferenceFilter show all
Defined in:
lib/banzai/filter/merge_request_reference_filter.rb

Overview

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 Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractReferenceFilter

#call, data_reference, #find_object_cached, #object_class, object_class_title, #object_class_title, #object_link_filter, #object_link_text, #object_link_title, object_name, object_sym, #object_sym, #project_from_ref_cache, referenced_by, references_in, #references_in, #url_for_object_cached

Methods included from CrossProjectReference

#project_from_ref

Methods inherited from ReferenceFilter

#data_attribute, #each_node, #element_node?, #escape_once, #ignore_ancestor_query, #project, #reference_class, referenced_by, #replace_link_node_with_href, #replace_link_node_with_text, #replace_text_when_pattern_matches, #text_node?, user_can_reference?, user_can_see_reference?, #validate, #yield_valid_link

Class Method Details

.object_classObject


8
9
10
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 8

def self.object_class
  MergeRequest
end

Instance Method Details

#find_object(project, id) ⇒ Object


12
13
14
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 12

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

22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 22

def object_link_text_extras(object, matches)
  extras = super

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

  extras
end

#url_for_object(mr, project) ⇒ Object


16
17
18
19
20
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 16

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