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
a7d4824d
Commit
a7d4824d
authored
Mar 29, 2019
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check mergeability in merge to ref service
and add spec Add changelog ok ok
parent
093629fe
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
14 deletions
+50
-14
app/models/merge_request.rb
app/models/merge_request.rb
+1
-2
app/services/merge_requests/merge_to_ref_service.rb
app/services/merge_requests/merge_to_ref_service.rb
+1
-3
changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml
...unreleased/check-mergeability-in-merge-to-ref-service.yml
+5
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+32
-0
spec/services/merge_requests/merge_to_ref_service_spec.rb
spec/services/merge_requests/merge_to_ref_service_spec.rb
+11
-9
No files found.
app/models/merge_request.rb
View file @
a7d4824d
...
@@ -807,8 +807,7 @@ class MergeRequest < ApplicationRecord
...
@@ -807,8 +807,7 @@ class MergeRequest < ApplicationRecord
end
end
def
mergeable_to_ref?
def
mergeable_to_ref?
return
false
if
merged?
return
false
unless
mergeable_state?
(
skip_ci_check:
true
,
skip_discussions_check:
true
)
return
false
if
broken?
# Given the `merge_ref_path` will have the same
# Given the `merge_ref_path` will have the same
# state the `target_branch` would have. Ideally
# state the `target_branch` would have. Ideally
...
...
app/services/merge_requests/merge_to_ref_service.rb
View file @
a7d4824d
...
@@ -41,9 +41,7 @@ module MergeRequests
...
@@ -41,9 +41,7 @@ module MergeRequests
super
super
error
=
error
=
if
Feature
.
disabled?
(
:merge_to_tmp_merge_ref_path
,
project
)
if
!
hooks_validation_pass?
(
merge_request
)
'Feature is not enabled'
elsif
!
hooks_validation_pass?
(
merge_request
)
hooks_validation_error
(
merge_request
)
hooks_validation_error
(
merge_request
)
elsif
!
@merge_request
.
mergeable_to_ref?
elsif
!
@merge_request
.
mergeable_to_ref?
"Merge request is not mergeable to
#{
target_ref
}
"
"Merge request is not mergeable to
#{
target_ref
}
"
...
...
changelogs/unreleased/check-mergeability-in-merge-to-ref-service.yml
0 → 100644
View file @
a7d4824d
---
title
:
Check mergeability in MergeToRefService
merge_request
:
26757
author
:
type
:
changed
spec/models/merge_request_spec.rb
View file @
a7d4824d
...
@@ -3081,6 +3081,38 @@ describe MergeRequest do
...
@@ -3081,6 +3081,38 @@ describe MergeRequest do
end
end
end
end
describe
'#mergeable_to_ref?'
do
it
'returns true when merge request is mergeable'
do
subject
=
create
(
:merge_request
)
expect
(
subject
.
mergeable_to_ref?
).
to
be
(
true
)
end
it
'returns false when merge request is already merged'
do
subject
=
create
(
:merge_request
,
:merged
)
expect
(
subject
.
mergeable_to_ref?
).
to
be
(
false
)
end
it
'returns false when merge request is closed'
do
subject
=
create
(
:merge_request
,
:closed
)
expect
(
subject
.
mergeable_to_ref?
).
to
be
(
false
)
end
it
'returns false when merge request is work in progress'
do
subject
=
create
(
:merge_request
,
title:
'WIP: The feature'
)
expect
(
subject
.
mergeable_to_ref?
).
to
be
(
false
)
end
it
'returns false when merge request has no commits'
do
subject
=
create
(
:merge_request
,
source_branch:
'empty-branch'
,
target_branch:
'master'
)
expect
(
subject
.
mergeable_to_ref?
).
to
be
(
false
)
end
end
describe
'#merge_participants'
do
describe
'#merge_participants'
do
it
'contains author'
do
it
'contains author'
do
expect
(
subject
.
merge_participants
).
to
eq
([
subject
.
author
])
expect
(
subject
.
merge_participants
).
to
eq
([
subject
.
author
])
...
...
spec/services/merge_requests/merge_to_ref_service_spec.rb
View file @
a7d4824d
...
@@ -40,15 +40,6 @@ describe MergeRequests::MergeToRefService do
...
@@ -40,15 +40,6 @@ describe MergeRequests::MergeToRefService do
end
end
shared_examples_for
'successfully evaluates pre-condition checks'
do
shared_examples_for
'successfully evaluates pre-condition checks'
do
it
'returns error when feature is disabled'
do
stub_feature_flags
(
merge_to_tmp_merge_ref_path:
false
)
result
=
service
.
execute
(
merge_request
)
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
'Feature is not enabled'
)
end
it
'returns an error when the failing to process the merge'
do
it
'returns an error when the failing to process the merge'
do
allow
(
project
.
repository
).
to
receive
(
:merge_to_ref
).
and_return
(
nil
)
allow
(
project
.
repository
).
to
receive
(
:merge_to_ref
).
and_return
(
nil
)
...
@@ -180,6 +171,17 @@ describe MergeRequests::MergeToRefService do
...
@@ -180,6 +171,17 @@ describe MergeRequests::MergeToRefService do
it
{
expect
(
todo
).
not_to
be_done
}
it
{
expect
(
todo
).
not_to
be_done
}
end
end
context
'when merge request is WIP state'
do
it
'fails to merge'
do
merge_request
=
create
(
:merge_request
,
title:
'WIP: The feature'
)
result
=
service
.
execute
(
merge_request
)
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
"Merge request is not mergeable to
#{
merge_request
.
merge_ref_path
}
"
)
end
end
it
'returns error when user has no authorization to admin the merge request'
do
it
'returns error when user has no authorization to admin the merge request'
do
unauthorized_user
=
create
(
:user
)
unauthorized_user
=
create
(
:user
)
project
.
add_reporter
(
unauthorized_user
)
project
.
add_reporter
(
unauthorized_user
)
...
...
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