Mark MR as merged regardless of errors when closing issues

We should mark the MR as merged as first thing on PostMergeService as in practice it is already merged on the repository. Happens that errors may happen when executing external services such as Issues::CloseService, and we do not want a MR hanging as opened because of that.
This commit is contained in:
Oswaldo Ferreira 2018-06-27 12:04:54 -03:00
parent c82b57789d
commit dba2d6ee7f
3 changed files with 19 additions and 1 deletions

View file

@ -6,9 +6,9 @@ module MergeRequests
#
class PostMergeService < MergeRequests::BaseService
def execute(merge_request)
merge_request.mark_as_merged
close_issues(merge_request)
todo_service.merge_merge_request(merge_request, current_user)
merge_request.mark_as_merged
create_event(merge_request)
create_note(merge_request)
notification_service.merge_mr(merge_request, current_user)

View file

@ -0,0 +1,5 @@
---
title: Mark MR as merged regardless of errors when closing issues
merge_request:
author:
type: fixed

View file

@ -47,5 +47,18 @@ describe MergeRequests::PostMergeService do
expect(diff_removal_service).to have_received(:execute)
end
it 'marks MR as merged regardless of errors when closing issues' do
merge_request.update(target_branch: 'foo')
allow(project).to receive(:default_branch).and_return('foo')
issue = create(:issue, project: project)
allow(merge_request).to receive(:closes_issues).and_return([issue])
allow_any_instance_of(Issues::CloseService).to receive(:execute).with(issue, commit: merge_request).and_raise
expect { described_class.new(project, user, {}).execute(merge_request) }.to raise_error
expect(merge_request.reload).to be_merged
end
end
end