Class: Gitlab::Triage::EntityBuilders::SummaryBuilder
- Inherits:
-
Object
- Object
- Gitlab::Triage::EntityBuilders::SummaryBuilder
- Defined in:
- lib/gitlab/triage/entity_builders/summary_builder.rb
Instance Method Summary collapse
- #any_resources? ⇒ Boolean
- #build_item(resource) ⇒ Object private
- #build_text(resource, template) ⇒ Object private
- #description ⇒ Object
- #description_resource ⇒ Object private
- #destination ⇒ Object
-
#initialize(type:, action:, resources:, network:, policy_spec: {}, separator: "\n") ⇒ SummaryBuilder
constructor
A new instance of SummaryBuilder.
- #items ⇒ Object private
- #title ⇒ Object
- #title_resource ⇒ Object private
- #valid? ⇒ Boolean
Constructor Details
#initialize(type:, action:, resources:, network:, policy_spec: {}, separator: "\n") ⇒ SummaryBuilder
Returns a new instance of SummaryBuilder.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 9 def initialize( type:, action:, resources:, network:, policy_spec: {}, separator: "\n") @type = type @policy_spec = policy_spec @item_template = action[:item] @title_template = action[:title] @summary_template = action[:summary] @summary_destination = action[:destination] @redact_confidentials = action[:redact_confidential_resources] != false @resources = resources @network = network @separator = separator end |
Instance Method Details
#any_resources? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 41 def any_resources? @resources.any? end |
#build_item(resource) ⇒ Object (private)
60 61 62 63 64 65 66 67 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 60 def build_item(resource) case resource when SummaryBuilder resource.description else build_text(resource, @item_template) end end |
#build_text(resource, template) ⇒ Object (private)
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 69 def build_text(resource, template) return '' unless template CommandBuilders::TextContentBuilder.new( template, resource: resource, network: @network, redact_confidentials: @redact_confidentials) .build_command.chomp end |
#description ⇒ Object
29 30 31 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 29 def description @description ||= build_text(description_resource, @summary_template) end |
#description_resource ⇒ Object (private)
51 52 53 54 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 51 def description_resource title_resource.merge( title: title, items: items, resources: @resources) end |
#destination ⇒ Object
33 34 35 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 33 def destination @summary_destination end |
#items ⇒ Object (private)
56 57 58 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 56 def items @items ||= @resources.map { |x| build_item(x) }.join(@separator) end |
#title ⇒ Object
25 26 27 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 25 def title @title ||= build_text(title_resource, @title_template) end |
#title_resource ⇒ Object (private)
47 48 49 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 47 def title_resource { type: @type } end |
#valid? ⇒ Boolean
37 38 39 |
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 37 def valid? title =~ /\S+/ && any_resources? end |