Class: Gitlab::Triage::EntityBuilders::SummaryBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/triage/entity_builders/summary_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(type:, action:, resources:, network:, policy_spec: {}, separator: "\n") ⇒ SummaryBuilder



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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
  @is_custom = policy_spec[:type] == 'custom'
end

Instance Method Details

#build_item(resource) ⇒ Object (private)



73
74
75
76
77
78
79
80
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 73

def build_item(resource)
  case resource
  when SummaryBuilder
    resource.description
  else
    build_text(resource, @item_template)
  end
end

#build_text(resource, template) ⇒ Object (private)



82
83
84
85
86
87
88
89
90
91
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 82

def build_text(resource, template)
  return '' unless template

  CommandBuilders::TextContentBuilder.new(
    template,
    resource: resource,
    network: @network,
    redact_confidentials: @redact_confidentials)
    .build_command.chomp
end

#content_available?Boolean

Check if this summary has content to include in a parent summary. Custom type summaries generate content from templates (external data), but only if the template produces non-empty output. Regular summaries need GitLab resources to generate content.



46
47
48
49
50
51
52
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 46

def content_available?
  if @is_custom
    /\S+/.match?(description)
  else
    @resources.any?
  end
end

#descriptionObject



30
31
32
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 30

def description
  @description ||= build_text(description_resource, @summary_template)
end

#description_resourceObject (private)



64
65
66
67
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 64

def description_resource
  title_resource.merge(
    title: title, items: items, resources: @resources)
end

#destinationObject



34
35
36
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 34

def destination
  @summary_destination
end

#itemsObject (private)



69
70
71
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 69

def items
  @items ||= @resources.map { |x| build_item(x) }.join(@separator)
end

#titleObject



26
27
28
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 26

def title
  @title ||= build_text(title_resource, @title_template)
end

#title_present?Boolean (private)



56
57
58
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 56

def title_present?
  /\S+/.match?(title)
end

#title_resourceObject (private)



60
61
62
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 60

def title_resource
  { type: @type }
end

#valid?Boolean



38
39
40
# File 'lib/gitlab/triage/entity_builders/summary_builder.rb', line 38

def valid?
  title_present? && content_available?
end