Commit 91a048ab authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-specialization-labels-via-danger' into 'master'

Danger: Automatically add specialization labels based on changes

See merge request gitlab-org/gitlab!40641
parents d8e7ed64 a1de1740
...@@ -59,11 +59,9 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any? ...@@ -59,11 +59,9 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
markdown(DB_MESSAGE) markdown(DB_MESSAGE)
markdown(DB_FILES_MESSAGE + helper.markdown_list(db_paths_to_review)) if db_paths_to_review.any? markdown(DB_FILES_MESSAGE + helper.markdown_list(db_paths_to_review)) if db_paths_to_review.any?
database_labels = helper.missing_database_labels(gitlab.mr_labels) unless has_database_scoped_labels?(gitlab.mr_labels)
if database_labels.any?
gitlab.api.update_merge_request(gitlab.mr_json['project_id'], gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'], gitlab.mr_json['iid'],
labels: (gitlab.mr_labels + database_labels).join(',')) add_labels: 'database::review pending')
end end
end end
...@@ -25,9 +25,3 @@ markdown(<<~MARKDOWN) ...@@ -25,9 +25,3 @@ markdown(<<~MARKDOWN)
- [Technical Writers assignments](https://about.gitlab.com/handbook/engineering/technical-writing/#designated-technical-writers) for the appropriate technical writer for this review. - [Technical Writers assignments](https://about.gitlab.com/handbook/engineering/technical-writing/#designated-technical-writers) for the appropriate technical writer for this review.
- [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review. - [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review.
MARKDOWN MARKDOWN
unless gitlab.mr_labels.include?('documentation')
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
labels: (gitlab.mr_labels + ['documentation']).join(','))
end
# frozen_string_literal: true
gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
return unless gitlab_danger.ci?
SPECIALIZATIONS = {
database: 'database',
backend: 'backend',
frontend: 'frontend',
docs: 'documentation',
qa: 'QA',
engineering_productivity: 'Engineering Productivity'
}.freeze
labels_to_add = helper.changes_by_category.each_with_object([]) do |(category, _changes), memo|
label = SPECIALIZATIONS.fetch(category, category.to_s)
memo << label unless 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
...@@ -206,16 +206,6 @@ module Gitlab ...@@ -206,16 +206,6 @@ module Gitlab
usernames.map { |u| Gitlab::Danger::Teammate.new('username' => u) } usernames.map { |u| Gitlab::Danger::Teammate.new('username' => u) }
end end
def missing_database_labels(current_mr_labels)
labels = if has_database_scoped_labels?(current_mr_labels)
['database']
else
['database', 'database::review pending']
end
labels - current_mr_labels
end
def sanitize_mr_title(title) def sanitize_mr_title(title)
title.gsub(DRAFT_REGEX, '').gsub(/`/, '\\\`') title.gsub(DRAFT_REGEX, '').gsub(/`/, '\\\`')
end end
...@@ -259,8 +249,6 @@ module Gitlab ...@@ -259,8 +249,6 @@ module Gitlab
all_changed_files.grep(regex) all_changed_files.grep(regex)
end end
private
def has_database_scoped_labels?(current_mr_labels) def has_database_scoped_labels?(current_mr_labels)
current_mr_labels.any? { |label| label.start_with?('database::') } current_mr_labels.any? { |label| label.start_with?('database::') }
end end
......
...@@ -22,6 +22,7 @@ class GitlabDanger ...@@ -22,6 +22,7 @@ class GitlabDanger
roulette roulette
ce_ee_vue_templates ce_ee_vue_templates
sidekiq_queues sidekiq_queues
specialization_labels
].freeze ].freeze
MESSAGE_PREFIX = '==>'.freeze MESSAGE_PREFIX = '==>'.freeze
......
...@@ -371,22 +371,6 @@ RSpec.describe Gitlab::Danger::Helper do ...@@ -371,22 +371,6 @@ RSpec.describe Gitlab::Danger::Helper do
end end
end end
describe '#missing_database_labels' do
subject { helper.missing_database_labels(current_mr_labels) }
context 'when current merge request has ~database::review pending' do
let(:current_mr_labels) { ['database::review pending', 'feature'] }
it { is_expected.to match_array(['database']) }
end
context 'when current merge request does not have ~database::review pending' do
let(:current_mr_labels) { ['feature'] }
it { is_expected.to match_array(['database', 'database::review pending']) }
end
end
describe '#sanitize_mr_title' do describe '#sanitize_mr_title' do
where(:mr_title, :expected_mr_title) do where(:mr_title, :expected_mr_title) do
'My MR title' | 'My MR title' 'My MR title' | 'My MR title'
......
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