Class: Banzai::Filter::MergeRequestReferenceFilter
- Inherits:
-
IssuableReferenceFilter
- Object
- HTML::Pipeline::Filter
- ReferenceFilter
- AbstractReferenceFilter
- IssuableReferenceFilter
- Banzai::Filter::MergeRequestReferenceFilter
- Defined in:
- lib/banzai/filter/merge_request_reference_filter.rb
Overview
HTML filter that replaces merge request references with links. References to merge requests that do not exist are ignored.
This filter supports cross-project references.
Constant Summary
Constants inherited from AbstractReferenceFilter
AbstractReferenceFilter::REFERENCE_PLACEHOLDER, AbstractReferenceFilter::REFERENCE_PLACEHOLDER_PATTERN
Class Method Summary collapse
Instance Method Summary collapse
- #data_attributes_for(text, parent, object, data = {}) ⇒ Object
- #object_link_text_extras(object, matches) ⇒ Object
- #object_link_title(object, matches) ⇒ Object
- #parent_records(parent, ids) ⇒ Object
- #reference_class(object_sym, options = {}) ⇒ Object
- #url_for_object(mr, project) ⇒ Object
Methods inherited from IssuableReferenceFilter
#find_object, #parent_from_ref, #record_identifier
Methods inherited from AbstractReferenceFilter
#call, #current_parent_path, #current_project_namespace_path, #find_for_paths, #find_object, #find_object_cached, #find_object_from_link, #find_object_from_link_cached, #from_ref_cached, identifier, #identifier, #object_class, #object_link_filter, #object_link_text, object_name, #object_sym, object_sym, #parent_per_reference, parse_symbol, #record_identifier, #records_per_parent, references_in, #references_in, #references_per_parent, #relation_for_paths, symbol_from_match, #url_for_object_cached, #wrap_link
Methods included from CrossProjectReference
Methods inherited from ReferenceFilter
call, #call_and_update_nodes, #data_attribute, #each_node, #element_node?, #group, #ignore_ancestor_query, #initialize, #nodes, #project, #replace_link_node_with_href, #replace_link_node_with_text, #replace_text_when_pattern_matches, #skip_project_check?, #text_node?, #user, #validate, #yield_valid_link
Methods included from OutputSafety
Methods included from RequestStoreReferenceCache
#cached_call, #get_or_set_cache
Constructor Details
This class inherits a constructor from Banzai::Filter::ReferenceFilter
Class Method Details
.object_class ⇒ Object
12 13 14 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 12 def self.object_class MergeRequest end |
Instance Method Details
#data_attributes_for(text, parent, object, data = {}) ⇒ Object
62 63 64 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 62 def data_attributes_for(text, parent, object, data = {}) super.merge(project_path: parent.full_path, iid: object.iid, mr_title: object.title) end |
#object_link_text_extras(object, matches) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 28 def object_link_text_extras(object, matches) extras = super if commit_ref = object_link_commit_ref(object, matches) klass = reference_class(:commit, tooltip: false) commit_ref_tag = %(<span class="#{klass}">#{commit_ref}</span>) return extras.unshift(commit_ref_tag) end path = matches[:path] if matches.names.include?("path") case path when '/diffs' extras.unshift "diffs" when '/commits' extras.unshift "commits" when '/builds' extras.unshift "builds" end extras end |
#object_link_title(object, matches) ⇒ Object
22 23 24 25 26 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 22 def object_link_title(object, matches) # The method will return `nil` if object is not a commit # allowing for properly handling the extended MR Tooltip object_link_commit_title(object, matches) end |
#parent_records(parent, ids) ⇒ Object
52 53 54 55 56 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 52 def parent_records(parent, ids) parent.merge_requests .where(iid: ids.to_a) .includes(target_project: :namespace) end |
#reference_class(object_sym, options = {}) ⇒ Object
58 59 60 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 58 def reference_class(object_sym, = {}) super(object_sym, tooltip: false) end |
#url_for_object(mr, project) ⇒ Object
16 17 18 19 20 |
# File 'lib/banzai/filter/merge_request_reference_filter.rb', line 16 def url_for_object(mr, project) h = Gitlab::Routing.url_helpers h.project_merge_request_url(project, mr, only_path: context[:only_path]) end |