Introduce comment_with_ruby and comment_with_ruby_file
In gitlab-org/quality/triage-ops!122 (merged) we're apparently abusing Ruby inside the comment
action, which the whole comment is under Ruby scripts and no plain text at all.
If we need to use it that way, it means we do want to have full Ruby support. So we can add comment_with_ruby
and comment_with_ruby_file
:
action:
comment_with_ruby: |
conditions = YAML.load_file('policies/add-stage-labels.yml')
.dig('resource_rules', 'issues', 'rules', 0, 'conditions')
.with_indifferent_access
all_labels = ExpandCondition::List.expand(conditions)
.flat_map { |condition| condition['labels'] }
.slice_before(/^section#/)
.group_by(&:first)
manage_control = all_labels.dig('section#manage_control' , 0)[1..-1]
if (resource[:labels] & manage_control).any?
puts '/label ~Manage ~"group:control" ~"devops:manage"'
end
comment_with_ruby_file: awesome.rb
So it can run in the context of a StringIO
like object, and we treat the StringIO#string
in the end as the comment. This way we can avoid noises and use pure Ruby.