Commit de4e63b3 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'cancel-auto-merge-when-branch-is-changed' into 'master'

Cancel Auto Merge when target branch is changed

See merge request gitlab-org/gitlab-ce!29416
parents e74f7159 30123910
......@@ -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])
......
......@@ -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
......@@ -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
......
......@@ -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
......
---
title: Cancel Auto Merge when target branch is changed
merge_request: 29416
author:
type: fixed
......@@ -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
......
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