Commit dba2d6ee authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

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.
parent c82b5778
No related merge requests found
......@@ -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)
......
---
title: Mark MR as merged regardless of errors when closing issues
merge_request:
author:
type: fixed
......@@ -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
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