Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1a18a942
Commit
1a18a942
authored
Oct 16, 2019
by
Winnie Hellmann
Committed by
Ash McKenzie
Oct 16, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Exclude people with no capacity from reviewer roulette
parent
a7e0f4de
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
14 deletions
+38
-14
lib/gitlab/danger/roulette.rb
lib/gitlab/danger/roulette.rb
+1
-1
lib/gitlab/danger/teammate.rb
lib/gitlab/danger/teammate.rb
+11
-1
spec/lib/gitlab/danger/roulette_spec.rb
spec/lib/gitlab/danger/roulette_spec.rb
+11
-5
spec/lib/gitlab/danger/teammate_spec.rb
spec/lib/gitlab/danger/teammate_spec.rb
+15
-7
No files found.
lib/gitlab/danger/roulette.rb
View file @
1a18a942
...
...
@@ -50,7 +50,7 @@ module Gitlab
# @param [Teammate] person
# @return [Boolean]
def
valid_person?
(
person
)
!
mr_author?
(
person
)
&&
!
person
.
out_of_offic
e?
!
mr_author?
(
person
)
&&
person
.
availabl
e?
end
# @param [Teammate] person
...
...
lib/gitlab/danger/teammate.rb
View file @
1a18a942
...
...
@@ -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
...
...
spec/lib/gitlab/danger/roulette_spec.rb
View file @
1a18a942
...
...
@@ -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"
)
...
...
spec/lib/gitlab/danger/teammate_spec.rb
View file @
1a18a942
...
...
@@ -135,17 +135,17 @@ describe Gitlab::Danger::Teammate do
end
end
describe
'#
out_of_offic
e?'
do
describe
'#
availabl
e?'
do
using
RSpec
::
Parameterized
::
TableSyntax
let
(
:capabilities
)
{
[
'dry head'
]
}
where
(
:status
,
:result
)
do
nil
|
fals
e
{
}
|
fals
e
{
message:
'
dear reader'
}
|
false
{
message:
'
OOO: massage'
}
|
tru
e
{
message:
'love it SOOO much'
}
|
tru
e
{}
|
tru
e
{
message:
'dear reader'
}
|
tru
e
{
message:
'
OOO: massage'
}
|
false
{
message:
'
love it SOOO much'
}
|
fals
e
{
emoji:
'red_circle'
}
|
fals
e
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment