Class: Gitlab::Triage::Action::CommentOnSummary
- Defined in:
- lib/gitlab/triage/action/comment_on_summary.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Dry
Instance Attribute Summary collapse
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
Attributes inherited from Base
Instance Method Summary collapse
- #act ⇒ Object
- #build_comment(resource) ⇒ Object private
- #build_post_url ⇒ Object private
-
#initialize(policy:, network:) ⇒ CommentOnSummary
constructor
A new instance of CommentOnSummary.
- #perform(comment) ⇒ Object private
- #sub_resource_type ⇒ Object private
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
#summary ⇒ Object (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
#act ⇒ Object
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_url ⇒ Object (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., 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..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_type ⇒ Object (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 |