Commit 1a18a942 authored by Winnie Hellmann's avatar Winnie Hellmann Committed by Ash McKenzie

Exclude people with no capacity from reviewer roulette

parent a7e0f4de
......@@ -50,7 +50,7 @@ module Gitlab
# @param [Teammate] person
# @return [Boolean]
def valid_person?(person)
!mr_author?(person) && !person.out_of_office?
!mr_author?(person) && person.available?
end
# @param [Teammate] person
......
......@@ -43,12 +43,22 @@ module Gitlab
nil # better no status than a crashing Danger
end
# @return [Boolean]
def available?
!out_of_office? && has_capacity?
end
private
# @return [Boolean]
def out_of_office?
status&.dig("message")&.match?(/OOO/i) || false
end
private
# @return [Boolean]
def has_capacity?
status&.dig("emoji") != 'red_circle'
end
def has_capability?(project, category, kind, labels)
case category
......
......@@ -104,11 +104,13 @@ describe Gitlab::Danger::Roulette do
let(:person2) { Gitlab::Danger::Teammate.new('username' => 'godfat') }
let(:author) { Gitlab::Danger::Teammate.new('username' => 'filipa') }
let(:ooo) { Gitlab::Danger::Teammate.new('username' => 'jacopo-beschi') }
let(:no_capacity) { Gitlab::Danger::Teammate.new('username' => 'uncharged') }
before do
stub_person_message(person1, 'making GitLab magic')
stub_person_message(person2, 'making GitLab magic')
stub_person_message(ooo, 'OOO till 15th')
stub_person_status(person1, message: 'making GitLab magic')
stub_person_status(person2, message: 'making GitLab magic')
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 should not fire request checking for her
......@@ -131,10 +133,14 @@ describe Gitlab::Danger::Roulette do
expect(subject.spin_for_person([author], random: Random.new)).to be_nil
end
it 'excludes person with no capacity' do
expect(subject.spin_for_person([no_capacity], random: Random.new)).to be_nil
end
private
def stub_person_message(person, message)
body = { message: message }.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")
......
......@@ -135,17 +135,17 @@ describe Gitlab::Danger::Teammate do
end
end
describe '#out_of_office?' do
describe '#available?' do
using RSpec::Parameterized::TableSyntax
let(:capabilities) { ['dry head'] }
where(:status, :result) do
nil | false
{} | false
{ message: 'dear reader' } | false
{ message: 'OOO: massage' } | true
{ message: 'love it SOOO much' } | true
{} | true
{ message: 'dear reader' } | true
{ message: 'OOO: massage' } | false
{ message: 'love it SOOO much' } | false
{ emoji: 'red_circle' } | false
end
with_them do
......@@ -154,7 +154,15 @@ describe Gitlab::Danger::Teammate do
.and_return(status&.stringify_keys)
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
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