Commit 30123910 authored by Shinya Maeda's avatar Shinya Maeda

Cancel Auto Merge when target branch is changed

When target branch is updated, Auto Merge should be canceled.
parent a0af3458
...@@ -68,6 +68,10 @@ module MergeRequests ...@@ -68,6 +68,10 @@ module MergeRequests
!merge_request.for_fork? !merge_request.for_fork?
end end
def cancel_auto_merge(merge_request)
AutoMergeService.new(project, current_user).cancel(merge_request)
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.
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def merge_requests_for(source_branch, mr_states: [:opened]) def merge_requests_for(source_branch, mr_states: [:opened])
......
...@@ -34,9 +34,5 @@ module MergeRequests ...@@ -34,9 +34,5 @@ module MergeRequests
merge_request_metrics_service(merge_request).close(close_event) merge_request_metrics_service(merge_request).close(close_event)
end end
end end
def cancel_auto_merge(merge_request)
AutoMergeService.new(project, current_user).cancel(merge_request)
end
end end
end end
...@@ -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_merge cancel_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_merge def cancel_auto_merges
merge_requests_for_source_branch.each do |merge_request| merge_requests_for_source_branch.each do |merge_request|
AutoMergeService.new(project, current_user).cancel(merge_request) cancel_auto_merge(merge_request)
end end
end end
......
...@@ -43,6 +43,8 @@ module MergeRequests ...@@ -43,6 +43,8 @@ module MergeRequests
create_branch_change_note(merge_request, 'target', create_branch_change_note(merge_request, 'target',
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)
end end
if merge_request.assignees != old_assignees if merge_request.assignees != old_assignees
......
---
title: Cancel Auto Merge when target branch is changed
merge_request: 29416
author:
type: fixed
...@@ -406,6 +406,18 @@ describe MergeRequests::UpdateService, :mailer do ...@@ -406,6 +406,18 @@ describe MergeRequests::UpdateService, :mailer do
expect(pending_todo.reload).to be_done expect(pending_todo.reload).to be_done
end end
end end
context 'when auto merge is enabled and target branch changed' do
before do
AutoMergeService.new(project, user).execute(merge_request, AutoMergeService::STRATEGY_MERGE_WHEN_PIPELINE_SUCCEEDS)
update_merge_request({ target_branch: 'target' })
end
it 'marks pending todos as done' do
expect(pending_todo.reload).to be_done
end
end
end end
context 'when the merge request is relabeled' do context 'when the merge request is relabeled' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment