Commit ce942cd9 authored by Ash McKenzie's avatar Ash McKenzie

Merge branch 'winh-roulette-rouge-routine' into 'master'

Exclude people with no capacity from reviewer roulette

See merge request gitlab-org/gitlab!17119
parents a7e0f4de 1a18a942
...@@ -50,7 +50,7 @@ module Gitlab ...@@ -50,7 +50,7 @@ module Gitlab
# @param [Teammate] person # @param [Teammate] person
# @return [Boolean] # @return [Boolean]
def valid_person?(person) def valid_person?(person)
!mr_author?(person) && !person.out_of_office? !mr_author?(person) && person.available?
end end
# @param [Teammate] person # @param [Teammate] person
......
...@@ -43,12 +43,22 @@ module Gitlab ...@@ -43,12 +43,22 @@ module Gitlab
nil # better no status than a crashing Danger nil # better no status than a crashing Danger
end end
# @return [Boolean]
def available?
!out_of_office? && has_capacity?
end
private
# @return [Boolean] # @return [Boolean]
def out_of_office? def out_of_office?
status&.dig("message")&.match?(/OOO/i) || false status&.dig("message")&.match?(/OOO/i) || false
end end
private # @return [Boolean]
def has_capacity?
status&.dig("emoji") != 'red_circle'
end
def has_capability?(project, category, kind, labels) def has_capability?(project, category, kind, labels)
case category case category
......
...@@ -104,11 +104,13 @@ describe Gitlab::Danger::Roulette do ...@@ -104,11 +104,13 @@ describe Gitlab::Danger::Roulette do
let(:person2) { Gitlab::Danger::Teammate.new('username' => 'godfat') } let(:person2) { Gitlab::Danger::Teammate.new('username' => 'godfat') }
let(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') } let(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') }
let(:ooo) { Gitlab::Danger::Teammate.new('username' => 'jacopo-beschi') } let(:ooo) { Gitlab::Danger::Teammate.new('username' => 'jacopo-beschi') }
let(:no_capacity) { Gitlab::Danger::Teammate.new('username' => 'uncharged') }
before do before do
stub_person_message(person1, 'making GitLab magic') stub_person_status(person1, message: 'making GitLab magic')
stub_person_message(person2, 'making GitLab magic') stub_person_status(person2, message: 'making GitLab magic')
stub_person_message(ooo, 'OOO till 15th') stub_person_status(ooo, message: 'OOO till 15th')
stub_person_status(no_capacity, message: 'At capacity for the next few days', emoji: 'red_circle')
# we don't stub Filipa, as she is the author and # we don't stub Filipa, as she is the author and
# we should not fire request checking for her # we should not fire request checking for her
...@@ -131,10 +133,14 @@ describe Gitlab::Danger::Roulette do ...@@ -131,10 +133,14 @@ describe Gitlab::Danger::Roulette do
expect(subject.spin_for_person([author], random: Random.new)).to be_nil expect(subject.spin_for_person([author], random: Random.new)).to be_nil
end end
it 'excludes person with no capacity' do
expect(subject.spin_for_person([no_capacity], random: Random.new)).to be_nil
end
private private
def stub_person_message(person, message) def stub_person_status(person, message: 'dummy message', emoji: 'unicorn')
body = { message: message }.to_json body = { message: message, emoji: emoji }.to_json
WebMock WebMock
.stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status") .stub_request(:get, "https://gitlab.com/api/v4/users/#{person.username}/status")
......
...@@ -135,17 +135,17 @@ describe Gitlab::Danger::Teammate do ...@@ -135,17 +135,17 @@ describe Gitlab::Danger::Teammate do
end end
end end
describe '#out_of_office?' do describe '#available?' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
let(:capabilities) { ['dry head'] } let(:capabilities) { ['dry head'] }
where(:status, :result) do where(:status, :result) do
nil | false {} | true
{} | false { message: 'dear reader' } | true
{ message: 'dear reader' } | false { message: 'OOO: massage' } | false
{ message: 'OOO: massage' } | true { message: 'love it SOOO much' } | false
{ message: 'love it SOOO much' } | true { emoji: 'red_circle' } | false
end end
with_them do with_them do
...@@ -154,7 +154,15 @@ describe Gitlab::Danger::Teammate do ...@@ -154,7 +154,15 @@ describe Gitlab::Danger::Teammate do
.and_return(status&.stringify_keys) .and_return(status&.stringify_keys)
end end
it { expect(subject.out_of_office?).to be result } it { expect(subject.available?).to be result }
end
it 'returns true if request fails' do
expect(Gitlab::Danger::RequestHelper).to receive(:http_get_json)
.exactly(2).times
.and_raise(Gitlab::Danger::RequestHelper::HTTPError.new)
expect(subject.available?).to be true
end end
end 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