Commit 49f26fe1 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'add-danger-bot-for-ci-templates' into 'master'

Add a new Danger task for CI/CD Templates Development

See merge request gitlab-org/gitlab!44688
parents 7c0b33c5 57ae4a5e
# frozen_string_literal: true
gitlab_danger = GitlabDanger.new(helper.gitlab_helper)
TEMPLATE_MESSAGE = <<~MSG
This merge request requires a CI/CD Template review. To make sure these
changes are reviewed, take the following steps:
1. Ensure the merge request has the ~"ci::templates" label.
If the merge request modifies CI/CD Template files, Danger will do this for you.
1. Prepare your MR for a CI/CD Template review according to the
[template development guide](https://docs.gitlab.com/ee/development/cicd/templates.html).
1. Assign and `@` mention the CI/CD Template reviewer suggested by Reviewer Roulette.
MSG
TEMPLATE_FILES_MESSAGE = <<~MSG
The following files require a review from the CI/CD Templates maintainers:
MSG
return unless gitlab_danger.ci?
template_paths_to_review = helper.changes_by_category[:ci_template]
if gitlab.mr_labels.include?('ci::templates') || template_paths_to_review.any?
message 'This merge request adds or changes files that require a ' \
'review from the CI/CD Templates maintainers.'
markdown(TEMPLATE_MESSAGE)
markdown(TEMPLATE_FILES_MESSAGE + helper.markdown_list(template_paths_to_review)) if template_paths_to_review.any?
end
......@@ -10,7 +10,8 @@ SPECIALIZATIONS = {
frontend: 'frontend',
docs: 'documentation',
qa: 'QA',
engineering_productivity: 'Engineering Productivity'
engineering_productivity: 'Engineering Productivity',
ci_template: 'ci::templates'
}.freeze
labels_to_add = helper.changes_by_category.each_with_object([]) do |(category, _changes), memo|
......
......@@ -123,7 +123,8 @@ module Gitlab
none: "",
qa: "~QA",
test: "~test ~Quality for `spec/features/*`",
engineering_productivity: '~"Engineering Productivity" for CI, Danger'
engineering_productivity: '~"Engineering Productivity" for CI, Danger',
ci_template: '~"ci::templates"'
}.freeze
# First-match win, so be sure to put more specific regex at the top...
CATEGORIES = {
......@@ -176,6 +177,8 @@ module Gitlab
%r{(CODEOWNERS)} => :engineering_productivity,
%r{(tests.yml)} => :engineering_productivity,
%r{\Alib/gitlab/ci/templates} => :ci_template,
%r{\A(ee/)?spec/features/} => :test,
%r{\A(ee/)?spec/support/shared_examples/features/} => :test,
%r{\A(ee/)?spec/support/shared_contexts/features/} => :test,
......
......@@ -52,6 +52,11 @@ module Gitlab
# Fetch an already picked backend maintainer, or pick one otherwise
spin.maintainer = backend_spin&.maintainer || spin_for_category(project, :backend, timezone_experiment: including_timezone).maintainer
end
when :ci_template
if spin.maintainer.nil?
# Fetch an already picked backend maintainer, or pick one otherwise
spin.maintainer = backend_spin&.maintainer || spin_for_category(project, :backend, timezone_experiment: including_timezone).maintainer
end
end
end
......
......@@ -284,7 +284,8 @@ RSpec.describe Gitlab::Danger::Helper do
'.codeclimate.yml' | [:engineering_productivity]
'.gitlab/CODEOWNERS' | [:engineering_productivity]
'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | [:backend]
'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | [:ci_template]
'lib/gitlab/ci/templates/dotNET-Core.yml' | [:ci_template]
'ee/FOO_VERSION' | [:unknown]
......@@ -376,6 +377,7 @@ RSpec.describe Gitlab::Danger::Helper do
:none | ''
:qa | '~QA'
:engineering_productivity | '~"Engineering Productivity" for CI, Danger'
:ci_template | '~"ci::templates"'
end
with_them do
......
......@@ -4,8 +4,11 @@ require 'webmock/rspec'
require 'timecop'
require 'gitlab/danger/roulette'
require 'active_support/testing/time_helpers'
RSpec.describe Gitlab::Danger::Roulette do
include ActiveSupport::Testing::TimeHelpers
around do |example|
travel_to(Time.utc(2020, 06, 22, 10)) { example.run }
end
......@@ -67,13 +70,25 @@ RSpec.describe Gitlab::Danger::Roulette do
)
end
let(:ci_template_reviewer) do
Gitlab::Danger::Teammate.new(
'username' => 'ci-template-maintainer',
'name' => 'CI Template engineer',
'role' => '~"ci::templates"',
'projects' => { 'gitlab' => 'reviewer ci_template' },
'available' => true,
'tz_offset_hours' => 2.0
)
end
let(:teammates) do
[
backend_maintainer.to_h,
frontend_maintainer.to_h,
frontend_reviewer.to_h,
software_engineer_in_test.to_h,
engineering_productivity_reviewer.to_h
engineering_productivity_reviewer.to_h,
ci_template_reviewer.to_h
]
end
......@@ -166,6 +181,14 @@ RSpec.describe Gitlab::Danger::Roulette do
end
end
context 'when change contains CI/CD Template category' do
let(:categories) { [:ci_template] }
it 'assigns CI/CD Template reviewer and fallback to backend maintainer' do
expect(spins).to eq([described_class::Spin.new(:ci_template, ci_template_reviewer, backend_maintainer, false, false)])
end
end
context 'when change contains test category' do
let(:categories) { [:test] }
......@@ -332,7 +355,8 @@ RSpec.describe Gitlab::Danger::Roulette do
frontend_reviewer,
frontend_maintainer,
software_engineer_in_test,
engineering_productivity_reviewer
engineering_productivity_reviewer,
ci_template_reviewer
])
end
......
......@@ -4,6 +4,7 @@ require 'timecop'
require 'rspec-parameterized'
require 'gitlab/danger/teammate'
require 'active_support/testing/time_helpers'
RSpec.describe Gitlab::Danger::Teammate do
using RSpec::Parameterized::TableSyntax
......@@ -148,6 +149,8 @@ RSpec.describe Gitlab::Danger::Teammate do
end
describe '#local_hour' do
include ActiveSupport::Testing::TimeHelpers
around do |example|
travel_to(Time.utc(2020, 6, 23, 10)) { example.run }
end
......
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