Class: Gitlab::Triage::Action::CommentOnSummary

Inherits:
Base
  • Object
show all
Defined in:
lib/gitlab/triage/action/comment_on_summary.rb

Direct Known Subclasses

Dry

Defined Under Namespace

Classes: Dry

Instance Attribute Summary collapse

Attributes inherited from Base

#network, #policy

Instance Method Summary collapse

Constructor Details

#initialize(policy:, network:) ⇒ CommentOnSummary

Returns a new instance of CommentOnSummary.



32
33
34
35
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 32

def initialize(policy:, network:)
  super(policy: policy, network: network)
  @summary = policy.summary
end

Instance Attribute Details

#summaryObject (readonly)

Returns the value of attribute summary.



30
31
32
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 30

def summary
  @summary
end

Instance Method Details

#actObject



37
38
39
40
41
42
43
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 37

def act
  policy.resources.each do |resource|
    comment = build_comment(resource).strip

    perform(comment) unless comment.empty?
  end
end

#build_comment(resource) ⇒ Object (private)



47
48
49
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 47

def build_comment(resource)
  CommandBuilders::TextContentBuilder.new(policy.actions[:comment_on_summary], resource: resource, network: network).build_command
end

#build_post_urlObject (private)



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 55

def build_post_url
  # POST /projects/:id/issues/:issue_iid/notes
  post_url = UrlBuilders::UrlBuilder.new(
    network_options: network.options,
    source_id: summary['project_id'],
    resource_type: policy.type,
    resource_id: summary['iid'],
    sub_resource_type: sub_resource_type
  ).build

  puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug

  post_url
end

#perform(comment) ⇒ Object (private)



51
52
53
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 51

def perform(comment)
  network.post_api(build_post_url, body: comment)
end

#sub_resource_typeObject (private)



70
71
72
73
74
75
76
77
78
79
# File 'lib/gitlab/triage/action/comment_on_summary.rb', line 70

def sub_resource_type
  case type = policy.actions[:comment_type]
  when 'comment', nil # nil is default
    'notes'
  when 'thread'
    'discussions'
  else
    raise ArgumentError, "Unknown comment type: #{type}"
  end
end