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 inherited from AbstractReferenceFilter

AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN

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_DATA_ATTRIBUTE

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_filter, #object_link_text, #object_link_text_extras, #parent, #parent_type, #parse_symbol, #record_identifier, #symbol_from_match, #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::OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

#initialize(*args) ⇒ CommitRangeReferenceFilter

Returns a new instance of CommitRangeReferenceFilter.



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

def initialize(*args)
  super

  @commit_map = {}
end

Instance Method Details

#find_object(project, id) ⇒ Object



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

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

  range = CommitRange.new(id, project)

  range.valid_commits? ? range : nil
end


39
40
41
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 39

def object_link_title(range, matches)
  nil
end

#references_in(text, pattern = object_reference_pattern) ⇒ Object



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

def references_in(text, pattern = object_reference_pattern)
  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



34
35
36
37
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 34

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