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
587ffd11
Commit
587ffd11
authored
Jun 26, 2019
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split AutoMergeService interfaces into two `cancel` and `abort`
Create explicit endpoint - abort.
parent
9414a41f
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
129 additions
and
15 deletions
+129
-15
app/services/auto_merge/base_service.rb
app/services/auto_merge/base_service.rb
+12
-2
app/services/auto_merge/merge_when_pipeline_succeeds_service.rb
...rvices/auto_merge/merge_when_pipeline_succeeds_service.rb
+7
-1
app/services/auto_merge_service.rb
app/services/auto_merge_service.rb
+6
-0
app/services/merge_requests/base_service.rb
app/services/merge_requests/base_service.rb
+2
-2
app/services/merge_requests/close_service.rb
app/services/merge_requests/close_service.rb
+1
-1
app/services/merge_requests/refresh_service.rb
app/services/merge_requests/refresh_service.rb
+3
-3
app/services/merge_requests/update_service.rb
app/services/merge_requests/update_service.rb
+1
-1
app/services/system_note_service.rb
app/services/system_note_service.rb
+10
-0
spec/services/auto_merge/base_service_spec.rb
spec/services/auto_merge/base_service_spec.rb
+35
-5
spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb
...s/auto_merge/merge_when_pipeline_succeeds_service_spec.rb
+11
-0
spec/services/auto_merge_service_spec.rb
spec/services/auto_merge_service_spec.rb
+25
-0
spec/services/system_note_service_spec.rb
spec/services/system_note_service_spec.rb
+16
-0
No files found.
app/services/auto_merge/base_service.rb
View file @
587ffd11
...
@@ -29,7 +29,7 @@ module AutoMerge
...
@@ -29,7 +29,7 @@ module AutoMerge
end
end
def
cancel
(
merge_request
)
def
cancel
(
merge_request
)
if
c
ancel_auto_merge
(
merge_request
)
if
c
lear_auto_merge_parameters
(
merge_request
)
yield
if
block_given?
yield
if
block_given?
success
success
...
@@ -38,6 +38,16 @@ module AutoMerge
...
@@ -38,6 +38,16 @@ module AutoMerge
end
end
end
end
def
abort
(
merge_request
,
reason
)
if
clear_auto_merge_parameters
(
merge_request
)
yield
if
block_given?
success
else
error
(
"Can't abort the automatic merge"
,
406
)
end
end
private
private
def
strategy
def
strategy
...
@@ -46,7 +56,7 @@ module AutoMerge
...
@@ -46,7 +56,7 @@ module AutoMerge
end
end
end
end
def
c
ancel_auto_merge
(
merge_request
)
def
c
lear_auto_merge_parameters
(
merge_request
)
merge_request
.
auto_merge_enabled
=
false
merge_request
.
auto_merge_enabled
=
false
merge_request
.
merge_user
=
nil
merge_request
.
merge_user
=
nil
...
...
app/services/auto_merge/merge_when_pipeline_succeeds_service.rb
View file @
587ffd11
...
@@ -19,7 +19,13 @@ module AutoMerge
...
@@ -19,7 +19,13 @@ module AutoMerge
def
cancel
(
merge_request
)
def
cancel
(
merge_request
)
super
do
super
do
SystemNoteService
.
cancel_merge_when_pipeline_succeeds
(
merge_request
,
@project
,
@current_user
)
SystemNoteService
.
cancel_merge_when_pipeline_succeeds
(
merge_request
,
project
,
current_user
)
end
end
def
abort
(
merge_request
,
reason
)
super
do
SystemNoteService
.
abort_merge_when_pipeline_succeeds
(
merge_request
,
project
,
current_user
,
reason
)
end
end
end
end
...
...
app/services/auto_merge_service.rb
View file @
587ffd11
...
@@ -42,6 +42,12 @@ class AutoMergeService < BaseService
...
@@ -42,6 +42,12 @@ class AutoMergeService < BaseService
get_service_instance
(
merge_request
.
auto_merge_strategy
).
cancel
(
merge_request
)
get_service_instance
(
merge_request
.
auto_merge_strategy
).
cancel
(
merge_request
)
end
end
def
abort
(
merge_request
,
reason
)
return
error
(
"Can't abort the automatic merge"
,
406
)
unless
merge_request
.
auto_merge_enabled?
get_service_instance
(
merge_request
.
auto_merge_strategy
).
abort
(
merge_request
,
reason
)
end
def
available_strategies
(
merge_request
)
def
available_strategies
(
merge_request
)
self
.
class
.
all_strategies
.
select
do
|
strategy
|
self
.
class
.
all_strategies
.
select
do
|
strategy
|
get_service_instance
(
strategy
).
available_for?
(
merge_request
)
get_service_instance
(
strategy
).
available_for?
(
merge_request
)
...
...
app/services/merge_requests/base_service.rb
View file @
587ffd11
...
@@ -68,8 +68,8 @@ module MergeRequests
...
@@ -68,8 +68,8 @@ module MergeRequests
!
merge_request
.
for_fork?
!
merge_request
.
for_fork?
end
end
def
cancel_auto_merge
(
merge_request
)
def
abort_auto_merge
(
merge_request
,
reason
)
AutoMergeService
.
new
(
project
,
current_user
).
cancel
(
merge_request
)
AutoMergeService
.
new
(
project
,
current_user
).
abort
(
merge_request
,
reason
)
end
end
# Returns all origin and fork merge requests from `@project` satisfying passed arguments.
# Returns all origin and fork merge requests from `@project` satisfying passed arguments.
...
...
app/services/merge_requests/close_service.rb
View file @
587ffd11
...
@@ -18,7 +18,7 @@ module MergeRequests
...
@@ -18,7 +18,7 @@ module MergeRequests
invalidate_cache_counts
(
merge_request
,
users:
merge_request
.
assignees
)
invalidate_cache_counts
(
merge_request
,
users:
merge_request
.
assignees
)
merge_request
.
update_project_counter_caches
merge_request
.
update_project_counter_caches
cleanup_environments
(
merge_request
)
cleanup_environments
(
merge_request
)
cancel_auto_merge
(
merge_request
)
abort_auto_merge
(
merge_request
,
'merge request was closed'
)
end
end
merge_request
merge_request
...
...
app/services/merge_requests/refresh_service.rb
View file @
587ffd11
...
@@ -24,7 +24,7 @@ module MergeRequests
...
@@ -24,7 +24,7 @@ module MergeRequests
reload_merge_requests
reload_merge_requests
outdate_suggestions
outdate_suggestions
refresh_pipelines_on_merge_requests
refresh_pipelines_on_merge_requests
cancel
_auto_merges
abort
_auto_merges
mark_pending_todos_done
mark_pending_todos_done
cache_merge_requests_closing_issues
cache_merge_requests_closing_issues
...
@@ -142,9 +142,9 @@ module MergeRequests
...
@@ -142,9 +142,9 @@ module MergeRequests
end
end
end
end
def
cancel
_auto_merges
def
abort
_auto_merges
merge_requests_for_source_branch
.
each
do
|
merge_request
|
merge_requests_for_source_branch
.
each
do
|
merge_request
|
cancel_auto_merge
(
merge_request
)
abort_auto_merge
(
merge_request
,
'source branch was updated'
)
end
end
end
end
...
...
app/services/merge_requests/update_service.rb
View file @
587ffd11
...
@@ -44,7 +44,7 @@ module MergeRequests
...
@@ -44,7 +44,7 @@ module MergeRequests
merge_request
.
previous_changes
[
'target_branch'
].
first
,
merge_request
.
previous_changes
[
'target_branch'
].
first
,
merge_request
.
target_branch
)
merge_request
.
target_branch
)
cancel_auto_merge
(
merge_request
)
abort_auto_merge
(
merge_request
,
'target branch was changed'
)
end
end
if
merge_request
.
assignees
!=
old_assignees
if
merge_request
.
assignees
!=
old_assignees
...
...
app/services/system_note_service.rb
View file @
587ffd11
...
@@ -234,6 +234,16 @@ module SystemNoteService
...
@@ -234,6 +234,16 @@ module SystemNoteService
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'merge'
))
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'merge'
))
end
end
# Called when 'merge when pipeline succeeds' is aborted
def
abort_merge_when_pipeline_succeeds
(
noteable
,
project
,
author
,
reason
)
body
=
"aborted the automatic merge because
#{
reason
}
"
##
# TODO: Abort message should be sent by the system, not a particular user.
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/63187.
create_note
(
NoteSummary
.
new
(
noteable
,
project
,
author
,
body
,
action:
'merge'
))
end
def
handle_merge_request_wip
(
noteable
,
project
,
author
)
def
handle_merge_request_wip
(
noteable
,
project
,
author
)
prefix
=
noteable
.
work_in_progress?
?
"marked"
:
"unmarked"
prefix
=
noteable
.
work_in_progress?
?
"marked"
:
"unmarked"
...
...
spec/services/auto_merge/base_service_spec.rb
View file @
587ffd11
...
@@ -121,11 +121,7 @@ describe AutoMerge::BaseService do
...
@@ -121,11 +121,7 @@ describe AutoMerge::BaseService do
end
end
end
end
describe
'#cancel'
do
shared_examples_for
'Canceled or Dropped'
do
subject
{
service
.
cancel
(
merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
:merge_when_pipeline_succeeds
)
}
it
'removes properies from the merge request'
do
it
'removes properies from the merge request'
do
subject
subject
...
@@ -173,6 +169,20 @@ describe AutoMerge::BaseService do
...
@@ -173,6 +169,20 @@ describe AutoMerge::BaseService do
it
'does not yield block'
do
it
'does not yield block'
do
expect
{
|
b
|
service
.
execute
(
merge_request
,
&
b
)
}.
not_to
yield_control
expect
{
|
b
|
service
.
execute
(
merge_request
,
&
b
)
}.
not_to
yield_control
end
end
end
end
describe
'#cancel'
do
subject
{
service
.
cancel
(
merge_request
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
:merge_when_pipeline_succeeds
)
}
it_behaves_like
'Canceled or Dropped'
context
'when failed to save'
do
before
do
allow
(
merge_request
).
to
receive
(
:save
)
{
false
}
end
it
'returns error status'
do
it
'returns error status'
do
expect
(
subject
[
:status
]).
to
eq
(
:error
)
expect
(
subject
[
:status
]).
to
eq
(
:error
)
...
@@ -180,4 +190,24 @@ describe AutoMerge::BaseService do
...
@@ -180,4 +190,24 @@ describe AutoMerge::BaseService do
end
end
end
end
end
end
describe
'#abort'
do
subject
{
service
.
abort
(
merge_request
,
reason
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
:merge_when_pipeline_succeeds
)
}
let
(
:reason
)
{
'an error'
}
it_behaves_like
'Canceled or Dropped'
context
'when failed to save'
do
before
do
allow
(
merge_request
).
to
receive
(
:save
)
{
false
}
end
it
'returns error status'
do
expect
(
subject
[
:status
]).
to
eq
(
:error
)
expect
(
subject
[
:message
]).
to
eq
(
"Can't abort the automatic merge"
)
end
end
end
end
end
spec/services/auto_merge/merge_when_pipeline_succeeds_service_spec.rb
View file @
587ffd11
...
@@ -177,6 +177,17 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do
...
@@ -177,6 +177,17 @@ describe AutoMerge::MergeWhenPipelineSucceedsService do
end
end
end
end
describe
"#abort"
do
before
do
service
.
abort
(
mr_merge_if_green_enabled
,
'an error'
)
end
it
'posts a system note'
do
note
=
mr_merge_if_green_enabled
.
notes
.
last
expect
(
note
.
note
).
to
include
'aborted the automatic merge'
end
end
describe
'pipeline integration'
do
describe
'pipeline integration'
do
context
'when there are multiple stages in the pipeline'
do
context
'when there are multiple stages in the pipeline'
do
let
(
:ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
let
(
:ref
)
{
mr_merge_if_green_enabled
.
source_branch
}
...
...
spec/services/auto_merge_service_spec.rb
View file @
587ffd11
...
@@ -161,4 +161,29 @@ describe AutoMergeService do
...
@@ -161,4 +161,29 @@ describe AutoMergeService do
end
end
end
end
end
end
describe
'#abort'
do
subject
{
service
.
abort
(
merge_request
,
error
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
:merge_when_pipeline_succeeds
)
}
let
(
:error
)
{
'an error'
}
it
'delegates to a relevant service instance'
do
expect_next_instance_of
(
AutoMerge
::
MergeWhenPipelineSucceedsService
)
do
|
service
|
expect
(
service
).
to
receive
(
:abort
).
with
(
merge_request
,
error
)
end
subject
end
context
'when auto merge is not enabled'
do
let
(
:merge_request
)
{
create
(
:merge_request
)
}
it
'returns error'
do
expect
(
subject
[
:message
]).
to
eq
(
"Can't abort the automatic merge"
)
expect
(
subject
[
:status
]).
to
eq
(
:error
)
expect
(
subject
[
:http_status
]).
to
eq
(
406
)
end
end
end
end
end
spec/services/system_note_service_spec.rb
View file @
587ffd11
...
@@ -359,6 +359,22 @@ describe SystemNoteService do
...
@@ -359,6 +359,22 @@ describe SystemNoteService do
end
end
end
end
describe
'.abort_merge_when_pipeline_succeeds'
do
let
(
:noteable
)
do
create
(
:merge_request
,
source_project:
project
,
target_project:
project
)
end
subject
{
described_class
.
abort_merge_when_pipeline_succeeds
(
noteable
,
project
,
author
,
'merge request was closed'
)
}
it_behaves_like
'a system note'
do
let
(
:action
)
{
'merge'
}
end
it
"posts the 'merge when pipeline succeeds' system note"
do
expect
(
subject
.
note
).
to
eq
"aborted the automatic merge because merge request was closed"
end
end
describe
'.change_title'
do
describe
'.change_title'
do
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
)
}
let
(
:noteable
)
{
create
(
:issue
,
project:
project
,
title:
'Lorem ipsum'
)
}
...
...
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