class Gitlab::Triage::Action::Comment
Public Instance Methods
act()
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 30 def act policy.resources.each do |resource| comment = build_comment(resource).strip perform(resource, comment) unless comment.empty? end end
Private Instance Methods
build_comment(resource)
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 40 def build_comment(resource) CommandBuilders::CommentCommandBuilder.new( [ CommandBuilders::TextContentBuilder.new(policy.actions[:comment], resource: resource, network: network).build_command, CommandBuilders::LabelCommandBuilder.new(policy.actions[:labels], resource: resource, network: network).build_command, CommandBuilders::RemoveLabelCommandBuilder.new(policy.actions[:remove_labels], resource: resource, network: network).build_command, CommandBuilders::CcCommandBuilder.new(policy.actions[:mention]).build_command, CommandBuilders::MoveCommandBuilder.new(policy.actions[:move]).build_command, CommandBuilders::StatusCommandBuilder.new(policy.actions[:status]).build_command ] ).build_command end
build_post_url(resource)
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 59 def build_post_url(resource) url_builder_opts = { network_options: network.options, source: policy.source, source_id: resource[policy.source_id_sym], resource_type: policy.type, resource_id: resource_id(resource), sub_resource_type: sub_resource_type } # POST /(groups|projects)/:id/(epics|issues|merge_requests)/:iid/notes post_url = UrlBuilders::UrlBuilder.new(url_builder_opts).build puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug post_url end
perform(resource, comment)
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 53 def perform(resource, comment) network.post_api( build_post_url(resource), body: comment) end
resource_id(resource)
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 88 def resource_id(resource) case policy.type when 'epics' resource['id'] else resource['iid'] end end
sub_resource_type()
click to toggle source
# File lib/gitlab/triage/action/comment.rb, line 77 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