Class: Banzai::Filter::References::ExternalIssueReferenceFilter
- Inherits:
-
ReferenceFilter
- Object
- HTML::Pipeline::Filter
- ReferenceFilter
- Banzai::Filter::References::ExternalIssueReferenceFilter
- Defined in:
- lib/banzai/filter/references/external_issue_reference_filter.rb
Overview
HTML filter that replaces external issue tracker references with links. References are ignored if the project doesn’t use an external issue tracker.
This filter does not support cross-project references.
Defined Under Namespace
Classes: LinkResolutionFilter
Constant Summary
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
Constants included from Concerns::PipelineTimingCheck
Concerns::PipelineTimingCheck::MAX_PIPELINE_SECONDS
Class Method Summary collapse
Instance Method Summary collapse
- #call ⇒ Object
-
#references_in(text, pattern = object_reference_pattern) ⇒ Object
Public: Find ‘JIRA-123` issue references in text.
Methods inherited from ReferenceFilter
call, #call_and_update_nodes, #each_node, #group, #initialize, #nodes, #nodes?, #object_class, #project, #requires_unescaping?
Methods included from Concerns::TextReplacer
#replace_references_in_text_with_html
Methods included from Concerns::HtmlWriter
Methods included from Concerns::OutputSafety
Methods included from RequestStoreReferenceCache
#cached_call, #get_or_set_cache
Methods included from Concerns::PipelineTimingCheck
Constructor Details
This class inherits a constructor from Banzai::Filter::References::ReferenceFilter
Class Method Details
.default_issues_tracker?(project) ⇒ Boolean
21 22 23 |
# File 'lib/banzai/filter/references/external_issue_reference_filter.rb', line 21 def self.default_issues_tracker?(project) external_issues_cached(project, :default_issues_tracker?) end |
.external_issues_cached(project, attribute) ⇒ Object
15 16 17 18 19 |
# File 'lib/banzai/filter/references/external_issue_reference_filter.rb', line 15 def self.external_issues_cached(project, attribute) cached_attributes = Gitlab::SafeRequestStore[:banzai_external_issues_tracker_attributes] ||= Hash.new { |h, k| h[k] = {} } cached_attributes[project.id][attribute] = project.public_send(attribute) if cached_attributes[project.id][attribute].nil? # rubocop:disable GitlabSecurity/PublicSend cached_attributes[project.id][attribute] end |
Instance Method Details
#call ⇒ Object
54 55 56 57 58 59 |
# File 'lib/banzai/filter/references/external_issue_reference_filter.rb', line 54 def call # Early return if the project isn't using an external tracker return doc if project.nil? || self.class.default_issues_tracker?(project) super end |
#references_in(text, pattern = object_reference_pattern) ⇒ Object
Public: Find ‘JIRA-123` issue references in text
references_in(text, pattern) do |match_text, issue|
"<a href=...>##{issue}</a>"
end
text - String text to search.
Yields the String text match and the String issue reference.
Returns a HTML String replaced with the return of the block.
See ReferenceFilter#references_in for a detailed discussion.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/banzai/filter/references/external_issue_reference_filter.rb', line 38 def references_in(text, pattern = object_reference_pattern) enumerator = case pattern when Regexp Gitlab::Utils::Gsub.gsub_with_limit(text, pattern, limit: Banzai::Filter::FILTER_ITEM_LIMIT) when Gitlab::UntrustedRegexp pattern.replace_gsub(text, limit: Banzai::Filter::FILTER_ITEM_LIMIT) else raise ArgumentError, "#{self.class.name} given #{pattern.class.name} pattern; should be Regexp or Gitlab::UntrustedRegexp" end replace_references_in_text_with_html(enumerator) do |match_data| yield match_data[0], match_data[:issue] end end |