Class: Banzai::Filter::References::CommitRangeReferenceFilter

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

Overview

HTML filter that replaces commit range references with links.

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 AbstractReferenceFilter

#call, #data_attributes_for, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, #identifier, #object_link_content_html, #object_link_content_html_extras, #object_link_filter, #parent, #parent_type, #parse_symbol, #record_identifier, #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, #nodes, #nodes?, #object_class, #project, #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

#initialize(*args) ⇒ CommitRangeReferenceFilter

Returns a new instance of CommitRangeReferenceFilter.



22
23
24
25
26
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 22

def initialize(*args)
  super

  @commit_map = {}
end

Instance Method Details

#find_object(project, id) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 28

def find_object(project, id)
  return unless project.is_a?(Project)

  range = CommitRange.new(id, project)

  range.valid_commits? ? range : nil
end


41
42
43
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 41

def object_link_title(range, matches)
  nil
end

#references_in(text, pattern = object_reference_pattern) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 13

def references_in(text, pattern = object_reference_pattern)
  replace_references_in_text_with_html(
    Gitlab::Utils::Gsub.gsub_with_limit(text, pattern,
      limit: Banzai::Filter::FILTER_ITEM_LIMIT)) do |match_data|
    yield match_data[0], match_data[:commit_range], match_data[:project], match_data[:namespace],
      match_data
  end
end

#url_for_object(range, project) ⇒ Object



36
37
38
39
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 36

def url_for_object(range, project)
  h = Gitlab::Routing.url_helpers
  h.project_compare_url(project, range.to_param.merge(only_path: context[:only_path]))
end