Class: Banzai::Filter::IssuableStateFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/banzai/filter/issuable_state_filter.rb

Overview

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

This filter supports cross-project references.

Constant Summary collapse

VISIBLE_STATES =
%w(closed merged).freeze

Instance Method Summary collapse

Instance Method Details

#callObject


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/banzai/filter/issuable_state_filter.rb', line 13

def call
  return doc unless context[:issuable_state_filter_enabled]

  context = RenderContext.new(project, current_user)
  extractor = Banzai::IssuableExtractor.new(context)
  issuables = extractor.extract([doc])

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

    if VISIBLE_STATES.include?(issuable.state) && issuable_reference?(node.inner_html, issuable)
      state = moved_issue?(issuable) ? s_("IssuableStatus|moved") : issuable.state
      node.content += " (#{state})"
    end
  end

  doc
end