Commit a1de1740 authored by Rémy Coutable's avatar Rémy Coutable

Danger: Automatically add specialization labels based on changes

I realized since we already detect the category of changes, we can
easily apply the relevant "specialization" labels based on that.
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent deb72ebb
......@@ -59,11 +59,9 @@ if gitlab.mr_labels.include?('database') || db_paths_to_review.any?
markdown(DB_MESSAGE)
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)
if database_labels.any?
unless has_database_scoped_labels?(gitlab.mr_labels)
gitlab.api.update_merge_request(gitlab.mr_json['project_id'],
gitlab.mr_json['iid'],
labels: (gitlab.mr_labels + database_labels).join(','))
gitlab.mr_json['iid'],
add_labels: 'database::review pending')
end
end
......@@ -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.
- [Documentation workflows](https://docs.gitlab.com/ee/development/documentation/workflow.html) for information on when to assign a merge request for review.
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
usernames.map { |u| Gitlab::Danger::Teammate.new('username' => u) }
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)
title.gsub(DRAFT_REGEX, '').gsub(/`/, '\\\`')
end
......@@ -259,8 +249,6 @@ module Gitlab
all_changed_files.grep(regex)
end
private
def has_database_scoped_labels?(current_mr_labels)
current_mr_labels.any? { |label| label.start_with?('database::') }
end
......
......@@ -22,6 +22,7 @@ class GitlabDanger
roulette
ce_ee_vue_templates
sidekiq_queues
specialization_labels
].freeze
MESSAGE_PREFIX = '==>'.freeze
......
......@@ -371,22 +371,6 @@ RSpec.describe Gitlab::Danger::Helper do
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
where(:mr_title, :expected_mr_title) do
'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