diff options
6 files changed, 26 insertions, 7 deletions
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index 2cfed62ce49..c34fbeb2adb 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -68,6 +68,10 @@ module MergeRequests !merge_request.for_fork? 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. # rubocop: disable CodeReuse/ActiveRecord def merge_requests_for(source_branch, mr_states: [:opened]) diff --git a/app/services/merge_requests/close_service.rb b/app/services/merge_requests/close_service.rb index b0f6166ea1c..b81a4dd81d2 100644 --- a/app/services/merge_requests/close_service.rb +++ b/app/services/merge_requests/close_service.rb @@ -34,9 +34,5 @@ module MergeRequests merge_request_metrics_service(merge_request).close(close_event) end end - - def cancel_auto_merge(merge_request) - AutoMergeService.new(project, current_user).cancel(merge_request) - end end end diff --git a/app/services/merge_requests/refresh_service.rb b/app/services/merge_requests/refresh_service.rb index 08130a531ee..4b199bd8fa8 100644 --- a/app/services/merge_requests/refresh_service.rb +++ b/app/services/merge_requests/refresh_service.rb @@ -24,7 +24,7 @@ module MergeRequests reload_merge_requests outdate_suggestions refresh_pipelines_on_merge_requests - cancel_auto_merge + cancel_auto_merges mark_pending_todos_done cache_merge_requests_closing_issues @@ -142,9 +142,9 @@ module MergeRequests end end - def cancel_auto_merge + def cancel_auto_merges merge_requests_for_source_branch.each do |merge_request| - AutoMergeService.new(project, current_user).cancel(merge_request) + cancel_auto_merge(merge_request) end end diff --git a/app/services/merge_requests/update_service.rb b/app/services/merge_requests/update_service.rb index 6a0f3000ffb..0066cd0491f 100644 --- a/app/services/merge_requests/update_service.rb +++ b/app/services/merge_requests/update_service.rb @@ -43,6 +43,8 @@ module MergeRequests create_branch_change_note(merge_request, 'target', merge_request.previous_changes['target_branch'].first, merge_request.target_branch) + + cancel_auto_merge(merge_request) end if merge_request.assignees != old_assignees diff --git a/changelogs/unreleased/cancel-auto-merge-when-branch-is-changed.yml b/changelogs/unreleased/cancel-auto-merge-when-branch-is-changed.yml new file mode 100644 index 00000000000..c3c6e4322a2 --- /dev/null +++ b/changelogs/unreleased/cancel-auto-merge-when-branch-is-changed.yml @@ -0,0 +1,5 @@ +--- +title: Cancel Auto Merge when target branch is changed +merge_request: 29416 +author: +type: fixed diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index fbfcd95e204..f566d235787 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -406,6 +406,18 @@ describe MergeRequests::UpdateService, :mailer do expect(pending_todo.reload).to be_done 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 context 'when the merge request is relabeled' do |