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
da7574dc
Commit
da7574dc
authored
Jan 15, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update participant_approvers for efficiency
parent
84b49c70
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
5 deletions
+37
-5
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+10
-5
ee/spec/models/merge_request_spec.rb
ee/spec/models/merge_request_spec.rb
+27
-0
No files found.
ee/app/models/ee/merge_request.rb
View file @
da7574dc
...
...
@@ -57,11 +57,16 @@ module EE
strong_memoize
(
:participant_approvers
)
do
next
[]
unless
approval_needed?
approvers
=
[]
approvers
.
concat
(
overall_approvers
(
exclude_code_owners:
true
))
approvers
.
concat
(
approvers_from_groups
)
::
User
.
where
(
id:
approvers
.
map
(
&
:id
)).
where
.
not
(
id:
approved_by_users
.
select
(
:id
))
if
::
Feature
.
enabled?
(
:approval_rule
)
approval_state
.
filtered_approvers
(
code_owner:
false
,
unactioned:
true
)
else
approvers
=
[
*
overall_approvers
(
exclude_code_owners:
true
),
*
approvers_from_groups
]
::
User
.
where
(
id:
approvers
.
map
(
&
:id
)).
where
.
not
(
id:
approved_by_users
.
select
(
:id
))
end
end
end
...
...
ee/spec/models/merge_request_spec.rb
View file @
da7574dc
...
...
@@ -17,10 +17,37 @@ describe MergeRequest do
end
describe
'#participant_approvers'
do
let
(
:approvers
)
{
create_list
(
:user
,
2
)
}
let
(
:code_owners
)
{
create_list
(
:user
,
2
)
}
let!
(
:regular_rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
users:
approvers
)
}
let!
(
:code_owner_rule
)
{
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
,
users:
code_owners
,
code_owner:
true
)
}
let!
(
:approval
)
{
create
(
:approval
,
merge_request:
merge_request
,
user:
approvers
.
last
)
}
before
do
allow
(
subject
).
to
receive
(
:code_owners
).
and_return
(
code_owners
)
end
it
'returns empty array if approval not needed'
do
allow
(
subject
).
to
receive
(
:approval_needed?
).
and_return
(
false
)
expect
(
subject
.
participant_approvers
).
to
be_empty
end
it
'returns approvers if approval is needed, excluding code owners'
do
allow
(
subject
).
to
receive
(
:approval_needed?
).
and_return
(
true
)
expect
(
subject
.
participant_approvers
).
to
contain_exactly
(
approvers
.
first
)
end
end
describe
'#participant_approvers with approval_rules disabled'
do
let!
(
:approver
)
{
create
(
:approver
,
target:
project
)
}
let
(
:code_owners
)
{
[
double
(
:code_owner
)]
}
before
do
stub_feature_flags
(
approval_rules:
false
)
allow
(
subject
).
to
receive
(
:code_owners
).
and_return
(
code_owners
)
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