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
3ef4e2d8
Commit
3ef4e2d8
authored
Jan 24, 2020
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added YARD annotations to ByApprovalsFinder and improved documentation
parent
595f44b2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
ee/app/finders/merge_requests/by_approvals_finder.rb
ee/app/finders/merge_requests/by_approvals_finder.rb
+29
-6
No files found.
ee/app/finders/merge_requests/by_approvals_finder.rb
View file @
3ef4e2d8
# frozen_string_literal: true
module
MergeRequests
# Used to filter MergeRequest
s
collections by approvers
# Used to filter MergeRequest collections by approvers
class
ByApprovalsFinder
attr_reader
:usernames
,
:ids
# We apply a limitation to the amount of elements that can be part of the filter condition
MAX_FILTER_ELEMENTS
=
5
# rubocop:disable CodeReuse/ActiveRecord
# Initialize the finder
#
# @param [Array<String>] usernames
# @param [Array<Integers>] ids
def
initialize
(
usernames
,
ids
)
# rubocop:disable CodeReuse/ActiveRecord
@usernames
=
Array
(
usernames
).
map
(
&
:to_s
).
uniq
.
take
(
MAX_FILTER_ELEMENTS
)
@ids
=
Array
(
ids
).
uniq
.
take
(
MAX_FILTER_ELEMENTS
)
# rubocop:enable CodeReuse/ActiveRecord
end
# rubocop:enable CodeReuse/ActiveRecord
# Filter MergeRequest collections by approvers
#
# @param [ActiveRecord::Relation] items the activerecord relation
def
execute
(
items
)
if
by_no_approvals?
without_approvals
(
items
)
...
...
@@ -32,25 +39,37 @@ module MergeRequests
private
# Is param using special condition: "None" ?
#
# @return [Boolean] whether special condition "None" is being used
def
by_no_approvals?
includes_
custom
_label?
(
IssuableFinder
::
FILTER_NONE
)
includes_
special
_label?
(
IssuableFinder
::
FILTER_NONE
)
end
# Is param using special condition: "Any" ?
#
# @return [Boolean] whether special condition "Any"" is being used
def
by_any_approvals?
includes_
custom
_label?
(
IssuableFinder
::
FILTER_ANY
)
includes_
special
_label?
(
IssuableFinder
::
FILTER_ANY
)
end
def
includes_custom_label?
(
label
)
# Check if we have the special label in ids or usernames field
#
# @param [String] label the special label
# @return [Boolean] whether ids or usernames includes the special label
def
includes_special_label?
(
label
)
ids
.
first
.
to_s
.
downcase
==
label
||
usernames
.
map
(
&
:downcase
).
include?
(
label
)
end
# Merge Requests without any approval
#
# @param [ActiveRecord::Relation] items
def
without_approvals
(
items
)
items
.
without_approvals
end
# Merge Requests with any number of approvals
#
# @param [ActiveRecord::Relation] items the activerecord relation
def
with_any_approvals
(
items
)
items
.
select_from_union
([
items
.
with_approvals
...
...
@@ -58,11 +77,15 @@ module MergeRequests
end
# Merge Requests approved by given usernames
#
# @param [ActiveRecord::Relation] items the activerecord relation
def
find_approved_by_names
(
items
)
items
.
approved_by_users_with_usernames
(
*
usernames
)
end
# Merge Requests approved by given user IDs
#
# @param [ActiveRecord::Relation] items the activerecord relation
def
find_approved_by_ids
(
items
)
items
.
approved_by_users_with_ids
(
*
ids
)
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