Class: Banzai::Filter::IssuableReferenceExpansionFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
lib/banzai/filter/issuable_reference_expansion_filter.rb

Overview

HTML filter that appends extra information to issuable links. Runs as a post-process filter as issuable might change while Markdown is in the cache.

This filter supports cross-project references.

Constant Summary collapse

NUMBER_OF_SUMMARY_ASSIGNEES =
2
VISIBLE_STATES =
%w[closed merged].freeze
EXTENDED_FORMAT_XPATH =
Gitlab::Utils::Nokogiri.css_to_xpath('a[data-reference-format="+s"]')

Instance Method Summary collapse

Instance Method Details

#callObject



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

def call
  return doc unless context[:issuable_reference_expansion_enabled]

  options = { extended_preload: doc.xpath(EXTENDED_FORMAT_XPATH).present? }
  extractor_context = RenderContext.new(project, current_user, options: options)

  extractor = Banzai::IssuableExtractor.new(extractor_context)
  issuables = extractor.extract([doc])

  issuables.each do |node, issuable|
    next if !can_read_cross_project? && cross_referenced?(issuable)
    next unless should_expand?(node, issuable)

    case node.attr('data-reference-format')
    when '+'
      expand_reference_with_title_and_state(node, issuable)
    when '+s'
      expand_reference_with_title_and_state(node, issuable)
      expand_reference_with_summary(node, issuable)
    else
      expand_reference_with_state(node, issuable)
    end
  end

  doc
end