Commit 86f43912 authored by Oswaldo Ferreira's avatar Oswaldo Ferreira

Cleans merge_jid when possible on MergeService

parent ffc576d7
...@@ -26,14 +26,13 @@ module MergeRequests ...@@ -26,14 +26,13 @@ module MergeRequests
merge_request.in_locked_state do merge_request.in_locked_state do
if commit if commit
after_merge after_merge
clean_merge_jid
success success
end end
end end
rescue MergeError => e rescue MergeError => e
clean_merge_jid
log_merge_error(e.message, save_message_on_model: true) log_merge_error(e.message, save_message_on_model: true)
ensure
# Make sure to clean up merge_jid in the end of the merge process.
merge_request.update_column(:merge_jid, nil)
end end
private private
...@@ -73,6 +72,10 @@ module MergeRequests ...@@ -73,6 +72,10 @@ module MergeRequests
end end
end end
def clean_merge_jid
merge_request.update_column(:merge_jid, nil)
end
def branch_deletion_user def branch_deletion_user
@merge_request.force_remove_source_branch? ? @merge_request.author : current_user @merge_request.force_remove_source_branch? ? @merge_request.author : current_user
end end
......
...@@ -12,13 +12,36 @@ describe MergeRequests::MergeService do ...@@ -12,13 +12,36 @@ describe MergeRequests::MergeService do
end end
describe '#execute' do describe '#execute' do
it 'cleans up merge_jid from MergeRequest' do context 'MergeRequest#merge_jid' do
merge_request.update_column(:merge_jid, 'hash-123') before do
service = described_class.new(project, user, commit_message: 'Awesome message') merge_request.update_column(:merge_jid, 'hash-123')
end
it 'is cleaned when no error is raised' do
service = described_class.new(project, user, commit_message: 'Awesome message')
service.execute(merge_request)
expect(merge_request.reload.merge_jid).to be_nil
end
service.execute(merge_request) it 'is cleaned when expected error is raised' do
service = described_class.new(project, user, commit_message: 'Awesome message')
allow(service).to receive(:commit).and_raise(described_class::MergeError)
expect(merge_request.reload.merge_jid).to be_nil service.execute(merge_request)
expect(merge_request.reload.merge_jid).to be_nil
end
it 'is not cleaned when unexpected error is raised' do
service = described_class.new(project, user, commit_message: 'Awesome message')
allow(service).to receive(:commit).and_raise(StandardError)
expect { service.execute(merge_request) }.to raise_error(StandardError)
expect(merge_request.reload.merge_jid).to be_present
end
end end
context 'valid params' do context 'valid params' 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