Commit 74399a90 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Show Test Automation Engineer for spec/feature as

reviewers.
parent deb0c1db
......@@ -33,10 +33,14 @@ MARKDOWN
def spin_for_category(team, project, category, branch_name)
random = roulette.new_random(branch_name)
labels = gitlab.mr_labels
reviewers = team.select { |member| member.reviewer?(project, category) }
traintainers = team.select { |member| member.traintainer?(project, category) }
maintainers = team.select { |member| member.maintainer?(project, category) }
reviewers, traintainers, maintainers =
%i[reviewer? traintainer? maintainer?].map do |kind|
team.select do |member|
member.public_send(kind, project, category, labels) # rubocop:disable GitlabSecurity/PublicSend
end
end
# TODO: take CODEOWNERS into account?
# https://gitlab.com/gitlab-org/gitlab-ce/issues/57653
......
......@@ -72,7 +72,8 @@ module Gitlab
CATEGORY_LABELS = {
docs: "~Documentation", # Docs are reviewed along DevOps stages, so don't need roulette for now.
none: "",
qa: "~QA"
qa: "~QA",
test: "~test for `spec/features/*`"
}.freeze
CATEGORIES = {
%r{\Adoc/} => :none, # To reinstate roulette for documentation, set to `:docs`.
......@@ -104,6 +105,7 @@ module Gitlab
%r{\A(ee/)?app/(?!assets|views)[^/]+} => :backend,
%r{\A(ee/)?(bin|config|danger|generator_templates|lib|rubocop|scripts)/} => :backend,
%r{\A(ee/)?spec/features/} => :test,
%r{\A(ee/)?spec/(?!javascripts|frontend)[^/]+} => :backend,
%r{\A(ee/)?vendor/(?!assets)[^/]+} => :backend,
%r{\A(ee/)?vendor/(languages\.yml|licenses\.csv)\z} => :backend,
......
......@@ -3,11 +3,12 @@
module Gitlab
module Danger
class Teammate
attr_reader :name, :username, :projects
attr_reader :name, :username, :role, :projects
def initialize(options = {})
@username = options['username']
@name = options['name'] || @username
@role = options['role']
@projects = options['projects']
end
......@@ -20,20 +21,32 @@ module Gitlab
end
# Traintainers also count as reviewers
def reviewer?(project, category)
capabilities(project).include?("reviewer #{category}") || traintainer?(project, category)
def reviewer?(project, category, labels)
has_capability?(project, category, :reviewer, labels) ||
traintainer?(project, category, labels)
end
def traintainer?(project, category)
capabilities(project).include?("trainee_maintainer #{category}")
def traintainer?(project, category, labels)
has_capability?(project, category, :trainee_maintainer, labels)
end
def maintainer?(project, category)
capabilities(project).include?("maintainer #{category}")
def maintainer?(project, category, labels)
has_capability?(project, category, :maintainer, labels)
end
private
def has_capability?(project, category, kind, labels)
case category
when :test
area = role[/Test Automation Engineer, (\w+)/, 1]
area && labels.any?(area) if kind == :reviewer
else
capabilities(project).include?("#{kind} #{category}")
end
end
def capabilities(project)
Array(projects.fetch(project, []))
end
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Admin Appearance' do
......
# frozen_string_literal: true
require 'spec_helper'
describe "Dashboard Issues Feed" do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Group merge requests page' do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Conversational Development Index' do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Issues' do
......
# frozen_string_literal: true
require "spec_helper"
describe "User merges a merge request", :js do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Project variables', :js do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Clusters', :js do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Pipeline', :js do
......
# frozen_string_literal: true
require 'spec_helper'
describe 'Project' do
......
# frozen_string_literal: true
require 'spec_helper'
describe "Profile access" do
......
......@@ -5,39 +5,66 @@ require 'fast_spec_helper'
require 'gitlab/danger/teammate'
describe Gitlab::Danger::Teammate do
subject { described_class.new({ 'projects' => projects }) }
subject { described_class.new(options) }
let(:options) { { 'projects' => projects, 'role' => role } }
let(:projects) { { project => capabilities } }
let(:role) { 'Engineer, Manage' }
let(:labels) { [] }
let(:project) { double }
describe 'multiple roles project project' do
let(:capabilities) { ['reviewer backend', 'maintainer frontend', 'trainee_maintainer database'] }
context 'when having multiple capabilities' do
let(:capabilities) { ['reviewer backend', 'maintainer frontend', 'trainee_maintainer qa'] }
it '#reviewer? supports multiple roles per project' do
expect(subject.reviewer?(project, :backend)).to be_truthy
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
end
it '#traintainer? supports multiple roles per project' do
expect(subject.traintainer?(project, :database)).to be_truthy
expect(subject.traintainer?(project, :qa, labels)).to be_truthy
end
it '#maintainer? supports multiple roles per project' do
expect(subject.maintainer?(project, :frontend)).to be_truthy
expect(subject.maintainer?(project, :frontend, labels)).to be_truthy
end
context 'when labels contain Create and the category is test' do
let(:labels) { ['Create'] }
context 'when role is Test Automation Engineer, Create' do
let(:role) { 'Test Automation Engineer, Create' }
it '#reviewer? returns true' do
expect(subject.reviewer?(project, :test, labels)).to be_truthy
end
it '#maintainer? returns false' do
expect(subject.maintainer?(project, :test, labels)).to be_falsey
end
end
context 'when role is Test Automation Engineer, Manage' do
let(:role) { 'Test Automation Engineer, Manage' }
it '#reviewer? returns false' do
expect(subject.reviewer?(project, :test, labels)).to be_falsey
end
end
end
end
describe 'one role project project' do
context 'when having single capability' do
let(:capabilities) { 'reviewer backend' }
it '#reviewer? supports one role per project' do
expect(subject.reviewer?(project, :backend)).to be_truthy
expect(subject.reviewer?(project, :backend, labels)).to be_truthy
end
it '#traintainer? supports one role per project' do
expect(subject.traintainer?(project, :database)).to be_falsey
expect(subject.traintainer?(project, :database, labels)).to be_falsey
end
it '#maintainer? supports one role per project' do
expect(subject.maintainer?(project, :frontend)).to be_falsey
expect(subject.maintainer?(project, :frontend, labels)).to be_falsey
end
end
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