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
d8fd48fa
Commit
d8fd48fa
authored
Jun 21, 2019
by
Oswaldo Ferreira
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid touching the MR status if MR is not opened
parent
c182f936
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
5 deletions
+34
-5
app/models/merge_request.rb
app/models/merge_request.rb
+0
-4
app/services/merge_requests/mergeability_check_service.rb
app/services/merge_requests/mergeability_check_service.rb
+10
-1
spec/services/merge_requests/mergeability_check_service_spec.rb
...ervices/merge_requests/mergeability_check_service_spec.rb
+24
-0
No files found.
app/models/merge_request.rb
View file @
d8fd48fa
...
...
@@ -233,10 +233,6 @@ class MergeRequest < ApplicationRecord
end
end
def
merge_ref_auto_sync_enabled?
Feature
.
enabled?
(
:merge_ref_auto_sync
,
project
,
default_enabled:
true
)
end
# Use this method whenever you need to make sure the head_pipeline is synced with the
# branch head commit, for example checking if a merge request can be merged.
# For more information check: https://gitlab.com/gitlab-org/gitlab-ce/issues/40004
...
...
app/services/merge_requests/mergeability_check_service.rb
View file @
d8fd48fa
...
...
@@ -4,7 +4,7 @@ module MergeRequests
class
MergeabilityCheckService
<
::
BaseService
include
Gitlab
::
Utils
::
StrongMemoize
delegate
:project
,
:merge_ref_auto_sync_enabled?
,
to: :@merge_request
delegate
:project
,
to: :@merge_request
delegate
:repository
,
to: :project
def
initialize
(
merge_request
)
...
...
@@ -39,6 +39,10 @@ module MergeRequests
return
ServiceResponse
.
error
(
message:
'Merge ref is outdated due to disabled feature'
)
end
unless
payload
.
fetch
(
:merge_ref_head
)
return
ServiceResponse
.
error
(
message:
'Merge ref cannot be updated'
)
end
ServiceResponse
.
success
(
payload:
payload
)
end
...
...
@@ -89,6 +93,7 @@ module MergeRequests
# Returns true if the merge-ref does not exists or is out of sync.
def
outdated_merge_ref?
return
false
unless
merge_ref_auto_sync_enabled?
return
false
unless
merge_request
.
open?
return
true
unless
ref_head
=
merge_request
.
merge_ref_head
return
true
unless
target_sha
=
merge_request
.
target_branch_sha
...
...
@@ -107,5 +112,9 @@ module MergeRequests
result
=
MergeRequests
::
MergeToRefService
.
new
(
project
,
merge_request
.
author
).
execute
(
merge_request
)
result
[
:status
]
==
:success
end
def
merge_ref_auto_sync_enabled?
Feature
.
enabled?
(
:merge_ref_auto_sync
,
project
,
default_enabled:
true
)
end
end
end
spec/services/merge_requests/mergeability_check_service_spec.rb
View file @
d8fd48fa
...
...
@@ -228,6 +228,30 @@ describe MergeRequests::MergeabilityCheckService do
end
end
context
'when MR is marked as mergeable, but repo is not mergeable and MR is not opened'
do
before
do
# Making sure that we don't touch the merge-status after
# the MR is not opened any longer. Source branch might
# have been removed, etc.
allow
(
merge_request
).
to
receive
(
:broken?
)
{
true
}
merge_request
.
mark_as_mergeable!
merge_request
.
close!
end
it
'returns ServiceResponse.error'
do
result
=
subject
expect
(
result
).
to
be_a
(
ServiceResponse
)
expect
(
result
.
error?
).
to
be
(
true
)
expect
(
result
.
message
).
to
eq
(
'Merge ref cannot be updated'
)
expect
(
result
.
payload
).
to
be_empty
end
it
'does not change the merge status'
do
expect
{
subject
}.
not_to
change
(
merge_request
,
:merge_status
).
from
(
'can_be_merged'
)
end
end
context
'when MR is mergeable but merge-ref does not exists'
do
before
do
merge_request
.
mark_as_mergeable!
...
...
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