Class: Gitlab::Triage::Action::Comment
- Inherits:
-
Base
- Object
- Base
- Gitlab::Triage::Action::Comment
show all
- Defined in:
- lib/gitlab/triage/action/comment.rb
Direct Known Subclasses
Dry
Defined Under Namespace
Classes: Dry
Instance Attribute Summary
Attributes inherited from Base
#network, #policy
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#act ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/gitlab/triage/action/comment.rb', line 30
def act
if policy.type == 'branches'
puts Gitlab::Triage::UI.warn "Comment actions are not available for branches. They will NOT be performed\n\n"
return
end
policy.resources.each do |resource|
= (resource).strip
perform(resource, ) unless .empty?
end
end
|
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/gitlab/triage/action/comment.rb', line 45
def (resource)
CommandBuilders::CommentCommandBuilder.new(
[
CommandBuilders::TextContentBuilder.new(
policy.actions[:comment],
resource: resource,
network: network,
redact_confidentials: policy.actions.fetch(:redact_confidential_resources, true)
).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) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/gitlab/triage/action/comment.rb', line 69
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_url = UrlBuilders::UrlBuilder.new(url_builder_opts).build
puts Gitlab::Triage::UI.debug "post_url: #{post_url}" if network.options.debug
post_url
end
|
63
64
65
66
67
|
# File 'lib/gitlab/triage/action/comment.rb', line 63
def perform(resource, )
network.post_api(
build_post_url(resource),
post_body())
end
|
#post_body(comment) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/gitlab/triage/action/comment.rb', line 107
def post_body()
body = { body: }
body[:internal] = true if policy.actions[:comment_internal]
body
end
|
#resource_id(resource) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/gitlab/triage/action/comment.rb', line 98
def resource_id(resource)
case policy.type
when 'epics'
resource['id']
else
resource['iid']
end
end
|
#sub_resource_type ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/gitlab/triage/action/comment.rb', line 87
def sub_resource_type
case type = policy.actions[:comment_type]
when 'comment', nil 'notes'
when 'thread'
'discussions'
else
raise ArgumentError, "Unknown comment type: #{type}"
end
end
|