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
9415d0b1
Commit
9415d0b1
authored
May 22, 2017
by
Jarka Kadlecova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check if a merge request is approved when using merge slash command
parent
bf993f70
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
0 deletions
+69
-0
app/models/merge_request.rb
app/models/merge_request.rb
+1
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+16
-0
spec/services/merge_requests/update_service_spec.rb
spec/services/merge_requests/update_service_spec.rb
+29
-0
spec/services/slash_commands/interpret_service_spec.rb
spec/services/slash_commands/interpret_service_spec.rb
+23
-0
No files found.
app/models/merge_request.rb
View file @
9415d0b1
...
...
@@ -967,6 +967,7 @@ 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
...
...
spec/models/merge_request_spec.rb
View file @
9415d0b1
...
...
@@ -1956,6 +1956,22 @@ describe MergeRequest, models: true do
expect
(
merge_request
.
mergeable_with_slash_command?
(
developer
,
last_diff_sha:
mr_sha
)).
to
be_truthy
end
end
context
'with approvals'
do
before
do
merge_request
.
target_project
.
update_attributes
(
approvals_before_merge:
1
)
end
it
'is not mergeable when not approved'
do
expect
(
merge_request
.
mergeable_with_slash_command?
(
developer
,
last_diff_sha:
mr_sha
)).
to
be_falsey
end
it
'is mergeable when approved'
do
merge_request
.
approvals
.
create
(
user:
user
)
expect
(
merge_request
.
mergeable_with_slash_command?
(
developer
,
last_diff_sha:
mr_sha
)).
to
be_truthy
end
end
end
end
...
...
spec/services/merge_requests/update_service_spec.rb
View file @
9415d0b1
...
...
@@ -230,6 +230,35 @@ describe MergeRequests::UpdateService, services: true do
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
end
context
'when not approved'
do
before
do
merge_request
.
update_attributes
(
approvals_before_merge:
1
)
perform_enqueued_jobs
do
service
.
execute
(
merge_request
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'opened'
)
}
end
context
'when approved'
do
before
do
merge_request
.
update_attributes
(
approvals_before_merge:
1
)
merge_request
.
approvals
.
create
(
user:
user
)
perform_enqueued_jobs
do
service
.
execute
(
merge_request
)
@merge_request
=
MergeRequest
.
find
(
merge_request
.
id
)
end
end
it
{
expect
(
@merge_request
).
to
be_valid
}
it
{
expect
(
@merge_request
.
state
).
to
eq
(
'merged'
)
}
end
end
context
'todos'
do
...
...
spec/services/slash_commands/interpret_service_spec.rb
View file @
9415d0b1
...
...
@@ -355,6 +355,29 @@ describe SlashCommands::InterpretService, services: true do
let
(
:issuable
)
{
build
(
:merge_request
,
source_project:
project
)
}
end
end
context
'not approved merge request can not be merged'
do
before
do
merge_request
.
target_project
.
update_attributes
(
approvals_before_merge:
1
)
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
"/merge"
}
let
(
:issuable
)
{
build
(
:merge_request
,
source_project:
project
)
}
end
end
context
'approved merge request can be merged'
do
before
do
merge_request
.
update_attributes
(
approvals_before_merge:
1
)
merge_request
.
approvals
.
create
(
user:
developer
)
end
it_behaves_like
'empty command'
do
let
(
:content
)
{
"/merge"
}
let
(
:issuable
)
{
build
(
:merge_request
,
source_project:
project
)
}
end
end
end
it_behaves_like
'title command'
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