Commit 4dc5f01d authored by Douwe Maan's avatar Douwe Maan

Merge branch 'reset_approval_on_push_for_changed_target' into 'master'

Fix: Approvals not reset if changing target branch

See merge request !1941
parents 4441f6fd 62251a23
...@@ -90,7 +90,7 @@ module MergeRequests ...@@ -90,7 +90,7 @@ module MergeRequests
target_project.reset_approvals_on_push && target_project.reset_approvals_on_push &&
merge_request.rebase_commit_sha != @newrev merge_request.rebase_commit_sha != @newrev
merge_request.approvals.destroy_all merge_request.approvals.delete_all
end end
end end
end end
......
...@@ -16,6 +16,7 @@ module MergeRequests ...@@ -16,6 +16,7 @@ module MergeRequests
if params[:force_remove_source_branch].present? if params[:force_remove_source_branch].present?
merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch) merge_request.merge_params['force_remove_source_branch'] = params.delete(:force_remove_source_branch)
end end
old_approvers = merge_request.overall_approvers.to_a old_approvers = merge_request.overall_approvers.to_a
handle_wip_event(merge_request) handle_wip_event(merge_request)
...@@ -48,6 +49,7 @@ module MergeRequests ...@@ -48,6 +49,7 @@ 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)
reset_approvals(merge_request)
end end
if merge_request.previous_changes.include?('milestone_id') if merge_request.previous_changes.include?('milestone_id')
...@@ -111,6 +113,14 @@ module MergeRequests ...@@ -111,6 +113,14 @@ module MergeRequests
private private
def reset_approvals(merge_request)
target_project = merge_request.target_project
if target_project.approvals_before_merge.nonzero? && target_project.reset_approvals_on_push
merge_request.approvals.delete_all
end
end
def handle_wip_event(merge_request) def handle_wip_event(merge_request)
if wip_event = params.delete(:wip_event) if wip_event = params.delete(:wip_event)
# We update the title that is provided in the params or we use the mr title # We update the title that is provided in the params or we use the mr title
......
---
title: 'Fix: Approvals not reset if changing target branch'
merge_request:
author:
...@@ -59,7 +59,7 @@ describe MergeRequests::UpdateService, services: true do ...@@ -59,7 +59,7 @@ describe MergeRequests::UpdateService, services: true do
end end
end end
it 'mathces base expectations' do it 'matches base expectations' do
expect(@merge_request).to be_valid expect(@merge_request).to be_valid
expect(@merge_request.title).to eq('New title') expect(@merge_request.title).to eq('New title')
expect(@merge_request.assignee).to eq(user2) expect(@merge_request.assignee).to eq(user2)
...@@ -531,6 +531,17 @@ describe MergeRequests::UpdateService, services: true do ...@@ -531,6 +531,17 @@ describe MergeRequests::UpdateService, services: true do
end end
end end
context 'updating target_branch' do
it 'resets approvals when target_branch is changed' do
merge_request.target_project.update(reset_approvals_on_push: true, approvals_before_merge: 2)
merge_request.approvals.create(user_id: user2.id)
update_merge_request(target_branch: 'video')
expect(merge_request.reload.approvals).to be_empty
end
end
context 'updating asssignee_id' do context 'updating asssignee_id' do
it 'does not update assignee when assignee_id is invalid' do it 'does not update assignee when assignee_id is invalid' do
merge_request.update(assignee_id: user.id) merge_request.update(assignee_id: user.id)
......
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