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
199262f0
Commit
199262f0
authored
May 22, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if an MR is approved when merging from API
parent
9415d0b1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
1 deletion
+46
-1
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
changelogs/unreleased-ee/2052-fix-merge-slash-approvals.yml
changelogs/unreleased-ee/2052-fix-merge-slash-approvals.yml
+4
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+20
-0
spec/requests/api/merge_requests_spec.rb
spec/requests/api/merge_requests_spec.rb
+21
-0
No files found.
app/models/merge_request.rb
View file @
199262f0
...
...
@@ -490,6 +490,7 @@ class MergeRequest < ActiveRecord::Base
end
def
mergeable?
(
skip_ci_check:
false
)
return
false
unless
approved?
return
false
unless
mergeable_state?
(
skip_ci_check:
skip_ci_check
)
check_if_can_be_merged
...
...
@@ -967,7 +968,6 @@ class MergeRequest < ActiveRecord::Base
def
mergeable_with_slash_command?
(
current_user
,
autocomplete_precheck:
false
,
last_diff_sha:
nil
)
return
false
unless
can_be_merged_by?
(
current_user
)
return
false
unless
approved?
return
true
if
autocomplete_precheck
...
...
changelogs/unreleased-ee/2052-fix-merge-slash-approvals.yml
0 → 100644
View file @
199262f0
---
title
:
Check if a merge request is approved when merging from API or slash command
merge_request
:
author
:
spec/models/merge_request_spec.rb
View file @
199262f0
...
...
@@ -1187,6 +1187,26 @@ describe MergeRequest, models: true do
expect
(
subject
.
mergeable?
).
to
be_truthy
end
context
'when using approvals'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
subject
).
to
receive
(
:mergeable_state?
).
and_return
(
true
)
subject
.
target_project
.
update_attributes
(
approvals_before_merge:
1
)
project
.
team
<<
[
user
,
:developer
]
end
it
'return false if not approved'
do
expect
(
subject
.
mergeable?
).
to
be_falsey
end
it
'return true if approved'
do
subject
.
approvals
.
create
(
user:
user
)
expect
(
subject
.
mergeable?
).
to
be_truthy
end
end
end
describe
'#mergeable_state?'
do
...
...
spec/requests/api/merge_requests_spec.rb
View file @
199262f0
...
...
@@ -635,6 +635,27 @@ describe API::MergeRequests do
expect
(
json_response
[
'message'
]).
to
eq
(
'405 Method Not Allowed'
)
end
it
'returns 405 if merge request was not approved'
do
project
.
team
<<
[
create
(
:user
),
:developer
]
project
.
update_attributes
(
approvals_before_merge:
1
)
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/merge"
,
user
)
expect
(
response
).
to
have_http_status
(
406
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Branch cannot be merged'
)
end
it
'returns 200 if merge request was approved'
do
approver
=
create
(
:user
)
project
.
team
<<
[
approver
,
:developer
]
project
.
update_attributes
(
approvals_before_merge:
1
)
merge_request
.
approvals
.
create
(
user:
approver
)
put
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/merge"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
end
it
"returns 401 if user has no permissions to merge"
do
user2
=
create
(
:user
)
project
.
team
<<
[
user2
,
:reporter
]
...
...
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