Commit 7c772beb authored by Rémy Coutable's avatar Rémy Coutable

danger: Don't warn for missing labels while adding some

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent cb5df34a
......@@ -17,6 +17,14 @@ end
anything_to_post = status_report.values.any? { |data| data.any? }
if helper.ci? && anything_to_post
return unless helper.ci?
if project_helper.labels_to_add.any?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: project_helper.labels_to_add.join(','))
end
if anything_to_post
markdown("**If needed, you can retry the [`danger-review` job](#{ENV['CI_JOB_URL']}) that generated this comment.**")
end
......@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
end
unless helper.has_database_scoped_labels?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: 'database::review pending')
project_helper.labels_to_add << 'database::review pending'
end
end
......@@ -58,9 +58,7 @@ def message_for_feature_flag_with_group!(feature_flag:, mr_group_label:)
return if feature_flag.group_match_mr_label?(mr_group_label)
if mr_group_label.nil?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: feature_flag.group)
project_helper.labels_to_add << feature_flag.group
else
fail %(`group` is set to ~"#{feature_flag.group}" in #{gitlab.html_link(feature_flag.path)}, which does not match ~"#{mr_group_label}" set on the MR!)
end
......
......@@ -13,12 +13,10 @@ MSG
# exit if not matching files or if no product intelligence labels
product_intelligence_paths_to_review = project_helper.changes_by_category[:product_intelligence]
labels = product_intelligence.missing_labels
labels_to_add = product_intelligence.missing_labels
return if product_intelligence_paths_to_review.empty? || labels.empty?
return if product_intelligence_paths_to_review.empty? || labels_to_add.empty?
warn format(CHANGED_FILES_MESSAGE, changed_files: helper.markdown_list(product_intelligence_paths_to_review))
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: labels)
project_helper.labels_to_add.concat(labels_to_add)
......@@ -19,8 +19,4 @@ labels_to_add = project_helper.changes_by_category.each_with_object([]) do |(cat
memo << label if label && !gitlab.mr_labels.include?(label)
end
if labels_to_add.any?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
add_labels: labels_to_add.join(','))
end
project_helper.labels_to_add.concat(labels_to_add) if labels_to_add.any?
......@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5
fail "Please provide a proper merge request description."
end
if (TYPE_LABELS & gitlab.mr_labels).empty?
if (TYPE_LABELS & (gitlab.mr_labels + project_helper.labels_to_add)).empty?
warn 'Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request.'
end
......
......@@ -118,6 +118,23 @@ However, you can speed these cycles up somewhat by emptying the
`.gitlab/ci/rails.gitlab-ci.yml` file in your merge request. Just don't forget
to revert the change before merging!
#### Adding labels via Danger
NOTE:
This is currently applicable to the [`gitlab-org/gitlab`](https://gitlab.com/gitlab-org/gitlab)
project only.
Danger is often used to improve MR hygiene by adding labels. Instead of calling the
API directly in your `Dangerfile`, add the labels to the `project_helper.labels_to_add` array.
The main `Dangerfile` will then take care of adding the labels to the MR with a single API call.
#### Shared rules and plugins
If the rule or plugin you implement can be useful for other projects, think about
upstreaming them to the [`gitlab-org/gitlab-dangerfiles`](https://gitlab.com/gitlab-org/gitlab-dangerfiles) project.
#### Enable Danger on a project
To enable the Dangerfile on another existing GitLab project, run the following
extra steps:
......
......@@ -22,12 +22,12 @@ module Tooling
ce_ee_vue_templates
ci_templates
datateam
metadata
feature_flag
roulette
sidekiq_queues
specialization_labels
specs
z_metadata
].freeze
MESSAGE_PREFIX = '==>'
......@@ -189,6 +189,10 @@ module Tooling
read_file(filename).lines(chomp: true)
end
def labels_to_add
@labels_to_add ||= []
end
private
def read_file(filename)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment