diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-06-18 14:18:50 +0300 |
commit | 8c7f4e9d5f36cff46365a7f8c4b9c21578c1e781 (patch) | |
tree | a77e7fe7a93de11213032ed4ab1f33a3db51b738 /spec/lib/gitlab/danger | |
parent | 00b35af3db1abfe813a778f643dad221aad51fca (diff) |
Add latest changes from gitlab-org/gitlab@13-1-stable-ee
Diffstat (limited to 'spec/lib/gitlab/danger')
-rw-r--r-- | spec/lib/gitlab/danger/changelog_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/gitlab/danger/helper_spec.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/danger/roulette_spec.rb | 183 |
3 files changed, 153 insertions, 36 deletions
diff --git a/spec/lib/gitlab/danger/changelog_spec.rb b/spec/lib/gitlab/danger/changelog_spec.rb index 8929374fb87..130a4708cec 100644 --- a/spec/lib/gitlab/danger/changelog_spec.rb +++ b/spec/lib/gitlab/danger/changelog_spec.rb @@ -65,9 +65,7 @@ describe Gitlab::Danger::Changelog do context 'added files contain a changelog' do [ 'changelogs/unreleased/entry.yml', - 'ee/changelogs/unreleased/entry.yml', - 'changelogs/unreleased-ee/entry.yml', - 'ee/changelogs/unreleased-ee/entry.yml' + 'ee/changelogs/unreleased/entry.yml' ].each do |file_path| let(:added_files) { [file_path] } diff --git a/spec/lib/gitlab/danger/helper_spec.rb b/spec/lib/gitlab/danger/helper_spec.rb index c2c881fd589..809064a540c 100644 --- a/spec/lib/gitlab/danger/helper_spec.rb +++ b/spec/lib/gitlab/danger/helper_spec.rb @@ -213,6 +213,7 @@ describe Gitlab::Danger::Helper do 'generator_templates/foo' | :backend 'vendor/languages.yml' | :backend 'vendor/licenses.csv' | :backend + 'file_hooks/examples/' | :backend 'Gemfile' | :backend 'Gemfile.lock' | :backend @@ -233,6 +234,7 @@ describe Gitlab::Danger::Helper do '.overcommit.yml.example' | :engineering_productivity '.editorconfig' | :engineering_productivity 'tooling/overcommit/foo' | :engineering_productivity + '.codeclimate.yml' | :engineering_productivity 'lib/gitlab/ci/templates/Security/SAST.gitlab-ci.yml' | :backend diff --git a/spec/lib/gitlab/danger/roulette_spec.rb b/spec/lib/gitlab/danger/roulette_spec.rb index 4d41e2c45aa..b6148cd1407 100644 --- a/spec/lib/gitlab/danger/roulette_spec.rb +++ b/spec/lib/gitlab/danger/roulette_spec.rb @@ -6,40 +6,149 @@ require 'webmock/rspec' require 'gitlab/danger/roulette' describe Gitlab::Danger::Roulette do + let(:backend_maintainer) do + { + username: 'backend-maintainer', + name: 'Backend maintainer', + role: 'Backend engineer', + projects: { 'gitlab' => 'maintainer backend' } + } + end + let(:frontend_reviewer) do + { + username: 'frontend-reviewer', + name: 'Frontend reviewer', + role: 'Frontend engineer', + projects: { 'gitlab' => 'reviewer frontend' } + } + end + let(:frontend_maintainer) do + { + username: 'frontend-maintainer', + name: 'Frontend maintainer', + role: 'Frontend engineer', + projects: { 'gitlab' => "maintainer frontend" } + } + end + let(:software_engineer_in_test) do + { + username: 'software-engineer-in-test', + name: 'Software Engineer in Test', + role: 'Software Engineer in Test, Create:Source Code', + projects: { + 'gitlab' => 'reviewer qa', + 'gitlab-qa' => 'maintainer' + } + } + end + let(:engineering_productivity_reviewer) do + { + username: 'eng-prod-reviewer', + name: 'EP engineer', + role: 'Engineering Productivity', + projects: { 'gitlab' => 'reviewer backend' } + } + end + let(:teammate_json) do - <<~JSON [ - { - "username": "in-gitlab-ce", - "name": "CE maintainer", - "projects":{ "gitlab-ce": "maintainer backend" } - }, - { - "username": "in-gitlab-ee", - "name": "EE reviewer", - "projects":{ "gitlab-ee": "reviewer frontend" } - } - ] - JSON + backend_maintainer, + frontend_maintainer, + frontend_reviewer, + software_engineer_in_test, + engineering_productivity_reviewer + ].to_json end - let(:ce_teammate_matcher) do + subject(:roulette) { Object.new.extend(described_class) } + + def matching_teammate(person) satisfy do |teammate| - teammate.username == 'in-gitlab-ce' && - teammate.name == 'CE maintainer' && - teammate.projects == { 'gitlab-ce' => 'maintainer backend' } + teammate.username == person[:username] && + teammate.name == person[:name] && + teammate.role == person[:role] && + teammate.projects == person[:projects] end end - let(:ee_teammate_matcher) do - satisfy do |teammate| - teammate.username == 'in-gitlab-ee' && - teammate.name == 'EE reviewer' && - teammate.projects == { 'gitlab-ee' => 'reviewer frontend' } + def matching_spin(category, reviewer: { username: nil }, maintainer: { username: nil }, optional: nil) + satisfy do |spin| + spin.category == category && + spin.reviewer&.username == reviewer[:username] && + spin.maintainer&.username == maintainer[:username] && + spin.optional_role == optional end end - subject(:roulette) { Object.new.extend(described_class) } + describe '#spin' do + let!(:project) { 'gitlab' } + let!(:branch_name) { 'a-branch' } + let!(:mr_labels) { ['backend', 'devops::create'] } + let!(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') } + + before do + [ + backend_maintainer, + frontend_reviewer, + frontend_maintainer, + software_engineer_in_test, + engineering_productivity_reviewer + ].each do |person| + stub_person_status(instance_double(Gitlab::Danger::Teammate, username: person[:username]), message: 'making GitLab magic') + end + + WebMock + .stub_request(:get, described_class::ROULETTE_DATA_URL) + .to_return(body: teammate_json) + allow(subject).to receive_message_chain(:gitlab, :mr_author).and_return(author.username) + allow(subject).to receive_message_chain(:gitlab, :mr_labels).and_return(mr_labels) + end + + context 'when change contains backend category' do + it 'assigns backend reviewer and maintainer' do + categories = [:backend] + spins = subject.spin(project, categories, branch_name) + + expect(spins).to contain_exactly(matching_spin(:backend, reviewer: engineering_productivity_reviewer, maintainer: backend_maintainer)) + end + end + + context 'when change contains frontend category' do + it 'assigns frontend reviewer and maintainer' do + categories = [:frontend] + spins = subject.spin(project, categories, branch_name) + + expect(spins).to contain_exactly(matching_spin(:frontend, reviewer: frontend_reviewer, maintainer: frontend_maintainer)) + end + end + + context 'when change contains QA category' do + it 'assigns QA reviewer and sets optional QA maintainer' do + categories = [:qa] + spins = subject.spin(project, categories, branch_name) + + expect(spins).to contain_exactly(matching_spin(:qa, reviewer: software_engineer_in_test, optional: :maintainer)) + end + end + + context 'when change contains Engineering Productivity category' do + it 'assigns Engineering Productivity reviewer and fallback to backend maintainer' do + categories = [:engineering_productivity] + spins = subject.spin(project, categories, branch_name) + + expect(spins).to contain_exactly(matching_spin(:engineering_productivity, reviewer: engineering_productivity_reviewer, maintainer: backend_maintainer)) + end + end + + context 'when change contains test category' do + it 'assigns corresponding SET and sets optional test maintainer' do + categories = [:test] + spins = subject.spin(project, categories, branch_name) + + expect(spins).to contain_exactly(matching_spin(:test, reviewer: software_engineer_in_test, optional: :maintainer)) + end + end + end describe '#team' do subject(:team) { roulette.team } @@ -76,7 +185,15 @@ describe Gitlab::Danger::Roulette do end it 'returns an array of teammates' do - is_expected.to contain_exactly(ce_teammate_matcher, ee_teammate_matcher) + expected_teammates = [ + matching_teammate(backend_maintainer), + matching_teammate(frontend_reviewer), + matching_teammate(frontend_maintainer), + matching_teammate(software_engineer_in_test), + matching_teammate(engineering_productivity_reviewer) + ] + + is_expected.to contain_exactly(*expected_teammates) end it 'memoizes the result' do @@ -86,7 +203,7 @@ describe Gitlab::Danger::Roulette do end describe '#project_team' do - subject { roulette.project_team('gitlab-ce') } + subject { roulette.project_team('gitlab-qa') } before do WebMock @@ -95,7 +212,7 @@ describe Gitlab::Danger::Roulette do end it 'filters team by project_name' do - is_expected.to contain_exactly(ce_teammate_matcher) + is_expected.to contain_exactly(matching_teammate(software_engineer_in_test)) end end @@ -136,15 +253,15 @@ describe Gitlab::Danger::Roulette do it 'excludes person with no capacity' do expect(subject.spin_for_person([no_capacity], random: Random.new)).to be_nil end + end - private + private - def stub_person_status(person, message: 'dummy message', emoji: 'unicorn') - body = { message: message, emoji: emoji }.to_json + def stub_person_status(person, message: 'dummy message', emoji: 'unicorn') + body = { message: message, emoji: emoji }.to_json - WebMock - .stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status") - .to_return(body: body) - end + WebMock + .stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status") + .to_return(body: body) end end |