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
7981eae9
Commit
7981eae9
authored
Jan 09, 2020
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use uniq values when filtering for approvals
parent
e0518bdc
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
13 deletions
+13
-13
ee/app/finders/merge_requests/by_approvals_finder.rb
ee/app/finders/merge_requests/by_approvals_finder.rb
+5
-5
ee/app/models/ee/merge_request.rb
ee/app/models/ee/merge_request.rb
+2
-2
ee/spec/finders/merge_requests/by_approvals_finder_spec.rb
ee/spec/finders/merge_requests/by_approvals_finder_spec.rb
+6
-6
No files found.
ee/app/finders/merge_requests/by_approvals_finder.rb
View file @
7981eae9
...
@@ -6,8 +6,8 @@ module MergeRequests
...
@@ -6,8 +6,8 @@ module MergeRequests
attr_reader
:usernames
,
:ids
attr_reader
:usernames
,
:ids
def
initialize
(
usernames
,
ids
)
def
initialize
(
usernames
,
ids
)
@usernames
=
usernames
.
to_a
.
map
(
&
:to_s
)
@usernames
=
Array
(
usernames
).
map
(
&
:to_s
).
uniq
@ids
=
ids
@ids
=
Array
(
ids
).
uniq
end
end
def
execute
(
items
)
def
execute
(
items
)
...
@@ -37,7 +37,7 @@ module MergeRequests
...
@@ -37,7 +37,7 @@ module MergeRequests
end
end
def
includes_custom_label?
(
label
)
def
includes_custom_label?
(
label
)
ids
.
to_s
.
downcase
==
label
||
usernames
.
map
(
&
:downcase
).
include?
(
label
)
ids
.
first
.
to_s
.
downcase
==
label
||
usernames
.
map
(
&
:downcase
).
include?
(
label
)
end
end
# Merge Requests without any approval
# Merge Requests without any approval
...
@@ -54,12 +54,12 @@ module MergeRequests
...
@@ -54,12 +54,12 @@ module MergeRequests
# Merge Requests approved by given usernames
# Merge Requests approved by given usernames
def
find_approved_by_names
(
items
)
def
find_approved_by_names
(
items
)
items
.
approved_by_users_with_usernames
(
usernames
)
items
.
approved_by_users_with_usernames
(
*
usernames
)
end
end
# Merge Requests approved by given user IDs
# Merge Requests approved by given user IDs
def
find_approved_by_ids
(
items
)
def
find_approved_by_ids
(
items
)
items
.
approved_by_users_with_ids
(
ids
)
items
.
approved_by_users_with_ids
(
*
ids
)
end
end
end
end
end
end
ee/app/models/ee/merge_request.rb
View file @
7981eae9
...
@@ -43,14 +43,14 @@ module EE
...
@@ -43,14 +43,14 @@ module EE
scope
:without_approvals
,
->
{
left_outer_joins
(
:approvals
).
where
(
approvals:
{
id:
nil
})
}
scope
:without_approvals
,
->
{
left_outer_joins
(
:approvals
).
where
(
approvals:
{
id:
nil
})
}
scope
:with_approvals
,
->
{
joins
(
:approvals
)
}
scope
:with_approvals
,
->
{
joins
(
:approvals
)
}
scope
:approved_by_users_with_ids
,
->
(
user_ids
)
do
scope
:approved_by_users_with_ids
,
->
(
*
user_ids
)
do
with_approvals
with_approvals
.
merge
(
Approval
.
with_user
)
.
merge
(
Approval
.
with_user
)
.
where
(
users:
{
id:
user_ids
})
.
where
(
users:
{
id:
user_ids
})
.
group
(
:id
)
.
group
(
:id
)
.
having
(
"COUNT(users.id) = ?"
,
user_ids
.
size
)
.
having
(
"COUNT(users.id) = ?"
,
user_ids
.
size
)
end
end
scope
:approved_by_users_with_usernames
,
->
(
usernames
)
do
scope
:approved_by_users_with_usernames
,
->
(
*
usernames
)
do
with_approvals
with_approvals
.
merge
(
Approval
.
with_user
)
.
merge
(
Approval
.
with_user
)
.
where
(
users:
{
username:
usernames
})
.
where
(
users:
{
username:
usernames
})
...
...
ee/spec/finders/merge_requests/by_approvals_finder_spec.rb
View file @
7981eae9
...
@@ -27,8 +27,8 @@ describe MergeRequests::ByApprovalsFinder do
...
@@ -27,8 +27,8 @@ describe MergeRequests::ByApprovalsFinder do
it
'returns merge requests without approvals'
do
it
'returns merge requests without approvals'
do
expected_result
=
[
merge_request_without_approvals
]
expected_result
=
[
merge_request_without_approvals
]
expect
(
merge_requests
(
ids:
'None'
)).
to
eq
(
expected_result
)
expect
(
merge_requests
(
ids:
'None'
)).
to
match_array
(
expected_result
)
expect
(
merge_requests
(
names:
[
'None'
])).
to
eq
(
expected_result
)
expect
(
merge_requests
(
names:
[
'None'
])).
to
match_array
(
expected_result
)
end
end
end
end
...
@@ -36,8 +36,8 @@ describe MergeRequests::ByApprovalsFinder do
...
@@ -36,8 +36,8 @@ describe MergeRequests::ByApprovalsFinder do
it
'returns merge requests approved by at least one user'
do
it
'returns merge requests approved by at least one user'
do
expected_result
=
[
merge_request_with_first_user_approval
,
merge_request_with_both_approvals
]
expected_result
=
[
merge_request_with_first_user_approval
,
merge_request_with_both_approvals
]
expect
(
merge_requests
(
ids:
'Any'
)).
to
eq
(
expected_result
)
expect
(
merge_requests
(
ids:
'Any'
)).
to
match_array
(
expected_result
)
expect
(
merge_requests
(
names:
[
'Any'
])).
to
eq
(
expected_result
)
expect
(
merge_requests
(
names:
[
'Any'
])).
to
match_array
(
expected_result
)
end
end
end
end
...
@@ -45,8 +45,8 @@ describe MergeRequests::ByApprovalsFinder do
...
@@ -45,8 +45,8 @@ describe MergeRequests::ByApprovalsFinder do
it
'returns merge requests approved by specific user'
do
it
'returns merge requests approved by specific user'
do
expected_result
=
[
merge_request_with_first_user_approval
,
merge_request_with_both_approvals
]
expected_result
=
[
merge_request_with_first_user_approval
,
merge_request_with_both_approvals
]
expect
(
merge_requests
(
ids:
[
first_user
.
id
])).
to
eq
(
expected_result
)
expect
(
merge_requests
(
ids:
[
first_user
.
id
])).
to
match_array
(
expected_result
)
expect
(
merge_requests
(
names:
[
first_user
.
username
])).
to
eq
(
expected_result
)
expect
(
merge_requests
(
names:
[
first_user
.
username
])).
to
match_array
(
expected_result
)
end
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