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

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

Returns:

  • (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

#descriptionObject



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_resourceObject (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

#destinationObject



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

def destination
  @summary_destination
end

#itemsObject (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

#titleObject



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_resourceObject (private)



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

def title_resource
  { type: @type }
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  title =~ /\S+/ && any_resources?
end