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

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

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

Methods included from OutputSafety

#escape_once

Methods included from RequestStoreReferenceCache

#cached_call, #get_or_set_cache

Constructor Details

#initialize(*args) ⇒ CommitRangeReferenceFilter

Returns a new instance of CommitRangeReferenceFilter.


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

def initialize(*args)
  super

  @commit_map = {}
end

Instance Method Details

#find_object(project, id) ⇒ Object


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

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
# File 'lib/banzai/filter/references/commit_range_reference_filter.rb', line 13

def references_in(text, pattern = object_reference_pattern)
  text.gsub(pattern) do |match|
    yield match, $~[:commit_range], $~[:project], $~[:namespace], $~
  end
end

#url_for_object(range, project) ⇒ Object


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

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