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
30ba0614
Commit
30ba0614
authored
Jan 29, 2019
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename to fallback_approvals_required
Fix spec so fallback path is tested
parent
2345197d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
12 deletions
+18
-12
ee/app/models/approval_state.rb
ee/app/models/approval_state.rb
+16
-6
ee/lib/ee/api/entities.rb
ee/lib/ee/api/entities.rb
+2
-5
ee/spec/requests/api/merge_request_approvals_spec.rb
ee/spec/requests/api/merge_request_approvals_spec.rb
+0
-1
No files found.
ee/app/models/approval_state.rb
View file @
30ba0614
...
...
@@ -44,20 +44,20 @@ class ApprovalState
return
false
unless
project
.
feature_available?
(
:merge_request_approvers
)
if
regular_rules
.
empty?
overall
_approvals_required
>
0
fallback
_approvals_required
>
0
else
wrapped_approval_rules
.
any?
{
|
rule
|
rule
.
approvals_required
>
0
}
end
end
def
overall
_approvals_required
@
overall
_approvals_required
||=
[
project
.
approvals_before_merge
,
merge_request
.
approvals_before_merge
||
0
].
max
def
fallback
_approvals_required
@
fallback
_approvals_required
||=
[
project
.
approvals_before_merge
,
merge_request
.
approvals_before_merge
||
0
].
max
end
def
approved?
strong_memoize
(
:approved
)
do
if
regular_rules
.
empty?
approvals
.
size
>=
overall
_approvals_required
approvals
.
size
>=
fallback
_approvals_required
else
wrapped_approval_rules
.
all?
(
&
:approved?
)
end
...
...
@@ -65,7 +65,17 @@ class ApprovalState
end
def
any_approver_allowed?
approved?
||
overall_approvals_required
>
approvers
.
size
approved?
end
def
approvals_required
strong_memoize
(
:approvals_required
)
do
if
regular_rules
.
empty?
[
project
.
approvals_before_merge
,
merge_request
.
approvals_before_merge
||
0
].
max
else
wrapped_approval_rules
.
sum
(
&
:approvals_required
)
end
end
end
# Number of approvals remaining (excluding existing approvals) before the MR is
...
...
@@ -73,7 +83,7 @@ class ApprovalState
def
approvals_left
strong_memoize
(
:approvals_left
)
do
if
regular_rules
.
empty?
[
overall
_approvals_required
-
approved_approvers
.
size
,
0
].
max
[
fallback
_approvals_required
-
approved_approvers
.
size
,
0
].
max
else
wrapped_approval_rules
.
sum
(
&
:approvals_left
)
end
...
...
ee/lib/ee/api/entities.rb
View file @
30ba0614
...
...
@@ -268,7 +268,7 @@ module EE
end
expose
:wrapped_approval_rules
,
as: :rules
,
using:
MergeRequestApprovalRule
expose
:
overall_approvals_required
,
as: :
fallback_approvals_required
expose
:fallback_approvals_required
end
# Decorates Project
...
...
@@ -332,10 +332,7 @@ module EE
expose
:approved?
,
as: :approved
# @deprecated, reads from first regular rule instead
expose
:approvals_required
do
|
approval_state
|
approval_state
.
first_regular_rule
&
.
approvals_required
end
expose
:approvals_required
expose
:approvals_left
...
...
ee/spec/requests/api/merge_request_approvals_spec.rb
View file @
30ba0614
...
...
@@ -522,7 +522,6 @@ describe "API::MergeRequestApprovals with approval_rule enabled" do
context
'when disable_overriding_approvers_per_merge_request is false on the project'
do
before
do
project
.
update
(
disable_overriding_approvers_per_merge_request:
false
)
create
(
:approval_merge_request_rule
,
merge_request:
merge_request
)
end
it
'allows you to override approvals required'
do
...
...
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