Commit 1fb310c9 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Merge branch...

Merge branch '343748-danger-can-prompt-for-type-label-even-when-danger-applies-the-type-label-itself' into 'master'

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

See merge request gitlab-org/gitlab!72987
parents 421703af 7c772beb
...@@ -17,6 +17,14 @@ end ...@@ -17,6 +17,14 @@ end
anything_to_post = status_report.values.any? { |data| data.any? } 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.**") markdown("**If needed, you can retry the [`danger-review` job](#{ENV['CI_JOB_URL']}) that generated this comment.**")
end end
...@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any? ...@@ -66,8 +66,6 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
end end
unless helper.has_database_scoped_labels? unless helper.has_database_scoped_labels?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'], project_helper.labels_to_add << 'database::review pending'
gitlab.mr_json['iid'],
add_labels: 'database::review pending')
end end
end end
...@@ -58,9 +58,7 @@ def message_for_feature_flag_with_group!(feature_flag:, mr_group_label:) ...@@ -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) return if feature_flag.group_match_mr_label?(mr_group_label)
if mr_group_label.nil? if mr_group_label.nil?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'], project_helper.labels_to_add << feature_flag.group
gitlab.mr_json['iid'],
add_labels: feature_flag.group)
else 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!) 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 end
......
...@@ -13,12 +13,10 @@ MSG ...@@ -13,12 +13,10 @@ MSG
# exit if not matching files or if no product intelligence labels # exit if not matching files or if no product intelligence labels
product_intelligence_paths_to_review = project_helper.changes_by_category[:product_intelligence] 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)) 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'], project_helper.labels_to_add.concat(labels_to_add)
gitlab.mr_json['iid'],
add_labels: labels)
...@@ -19,8 +19,4 @@ labels_to_add = project_helper.changes_by_category.each_with_object([]) do |(cat ...@@ -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) memo << label if label && !gitlab.mr_labels.include?(label)
end end
if labels_to_add.any? project_helper.labels_to_add.concat(labels_to_add) 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
...@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5 ...@@ -18,7 +18,7 @@ if gitlab.mr_body.size < 5
fail "Please provide a proper merge request description." fail "Please provide a proper merge request description."
end 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.' warn 'Please add a [merge request type](https://about.gitlab.com/handbook/engineering/metrics/#work-type-classification) to this merge request.'
end end
......
...@@ -118,6 +118,23 @@ However, you can speed these cycles up somewhat by emptying the ...@@ -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 `.gitlab/ci/rails.gitlab-ci.yml` file in your merge request. Just don't forget
to revert the change before merging! 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 To enable the Dangerfile on another existing GitLab project, run the following
extra steps: extra steps:
......
...@@ -22,12 +22,12 @@ module Tooling ...@@ -22,12 +22,12 @@ module Tooling
ce_ee_vue_templates ce_ee_vue_templates
ci_templates ci_templates
datateam datateam
metadata
feature_flag feature_flag
roulette roulette
sidekiq_queues sidekiq_queues
specialization_labels specialization_labels
specs specs
z_metadata
].freeze ].freeze
MESSAGE_PREFIX = '==>' MESSAGE_PREFIX = '==>'
...@@ -189,6 +189,10 @@ module Tooling ...@@ -189,6 +189,10 @@ module Tooling
read_file(filename).lines(chomp: true) read_file(filename).lines(chomp: true)
end end
def labels_to_add
@labels_to_add ||= []
end
private private
def read_file(filename) 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