Class: Banzai::Filter::References::MergeRequestReferenceFilter

Inherits:
IssuableReferenceFilter show all
Defined in:
lib/banzai/filter/references/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.

Constant Summary

Constants included from Concerns::TimeoutFilterHandler

Concerns::TimeoutFilterHandler::COMPLEX_MARKDOWN_MESSAGE, Concerns::TimeoutFilterHandler::RENDER_TIMEOUT, Concerns::TimeoutFilterHandler::SANITIZATION_RENDER_TIMEOUT

Constants included from Concerns::PipelineTimingCheck

Concerns::PipelineTimingCheck::MAX_PIPELINE_SECONDS

Constants inherited from ReferenceFilter

ReferenceFilter::REFERENCE_TYPE_ATTRIBUTE, ReferenceFilter::REFERENCE_TYPE_DATA_ATTRIBUTE_NAME

Constants included from Concerns::TextReplacer

Concerns::TextReplacer::REFERENCE_PLACEHOLDER, Concerns::TextReplacer::REFERENCE_PLACEHOLDER_PATTERN

Instance Method Summary collapse

Methods inherited from IssuableReferenceFilter

#find_object, #record_identifier

Methods inherited from AbstractReferenceFilter

#call, #find_object, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, #initialize, #object_link_content_html, #object_link_filter, #object_link_title, #parent, #parent_type, #parse_symbol, #record_identifier, #references_in, #symbol_from_match_data, #url_for_object_cached, #wrap_link

Methods included from CrossProjectReference

#parent_from_ref

Methods included from Concerns::TimeoutFilterHandler

#call

Methods included from Concerns::PipelineTimingCheck

#call, #exceeded_pipeline_max?

Methods inherited from ReferenceFilter

call, #call, #call_and_update_nodes, #each_node, #group, #initialize, #nodes, #nodes?, #object_class, #project, #references_in, #requires_unescaping?

Methods included from Concerns::TextReplacer

#replace_references_in_text_with_html

Methods included from Concerns::HtmlWriter

#write_opening_tag

Methods included from Concerns::OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

This class inherits a constructor from Banzai::Filter::References::AbstractReferenceFilter

Instance Method Details

#data_attributes_for(original, parent, object, **data) ⇒ Object



58
59
60
# File 'lib/banzai/filter/references/merge_request_reference_filter.rb', line 58

def data_attributes_for(original, parent, object, **data)
  super.merge(project_path: parent.full_path, iid: object.iid)
end


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/banzai/filter/references/merge_request_reference_filter.rb', line 19

def object_link_content_html_extras(object, matches)
  extras = super

  if commit_ref = object_link_commit_ref(object, matches)
    klass = reference_class(:commit, tooltip: false)

    commit_ref_tag = doc.document.create_element("span")
    commit_ref_tag['class'] = klass
    commit_ref_tag.content = commit_ref

    return extras.unshift(commit_ref_tag.to_html)
  end

  path = matches[:path] if matches.names.include?("path")

  case path
  when '/diffs'
    extras.unshift CGI.escapeHTML("diffs")
  when '/commits'
    extras.unshift CGI.escapeHTML("commits")
  when '/builds'
    extras.unshift CGI.escapeHTML("builds")
  end

  extras
end

#parent_records(parent, ids) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/banzai/filter/references/merge_request_reference_filter.rb', line 46

def parent_records(parent, ids)
  return MergeRequest.none unless parent.is_a?(Project)

  parent.merge_requests
    .iid_in(ids.to_a)
    .includes(target_project: :namespace)
end

#reference_class(object_sym, tooltip: false) ⇒ Object



54
55
56
# File 'lib/banzai/filter/references/merge_request_reference_filter.rb', line 54

def reference_class(object_sym, tooltip: false)
  super
end

#url_for_object(mr, project) ⇒ Object



14
15
16
17
# File 'lib/banzai/filter/references/merge_request_reference_filter.rb', line 14

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