class Gitlab::Triage::Action::CommentOnSummary

Attributes

summary[R]

Public Class Methods

new(policy:, network:) click to toggle source
Calls superclass method Gitlab::Triage::Action::Base::new
# File lib/gitlab/triage/action/comment_on_summary.rb, line 32
def initialize(policy:, network:)
  super(policy: policy, network: network)
  @summary = policy.summary
end

Public Instance Methods

act() click to toggle source
# 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

Private Instance Methods

build_comment(resource) click to toggle source
# 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_url() click to toggle source
# 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) click to toggle source
# 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_type() click to toggle source
# 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