Commit 0efbf790 authored by Robert Speicher's avatar Robert Speicher

Merge branch '1852-custom-hook-errors-don-t-display-in-merge-request-widget' into 'master'

Resolve "Custom hook errors don't display in merge request widget"

Closes #1852

See merge request !1375
parents 9b187ddd 65ba1dc7
......@@ -13,6 +13,10 @@ module MergeRequests
source,
merge_request.target_branch,
merge_request: merge_request)
rescue GitHooksService::PreReceiveError => e
raise MergeError, e.message
rescue StandardError => e
raise MergeError, "Something went wrong during merge: #{e.message}"
ensure
merge_request.update(in_progress_merge_commit_sha: nil)
end
......
---
title: Show hook errors for fast-forward merges
merge_request: 1375
author:
......@@ -16,7 +16,7 @@ describe MergeRequests::FfMergeService do
project.team << [user2, :developer]
end
describe :execute do
describe '#execute' do
context 'valid params' do
let(:service) { MergeRequests::FfMergeService.new(project, user, {}) }
......@@ -48,5 +48,37 @@ describe MergeRequests::FfMergeService do
expect(note.note).to include 'merged'
end
end
context "error handling" do
let(:service) { MergeRequests::FfMergeService.new(project, user, commit_message: 'Awesome message') }
before do
allow(Rails.logger).to receive(:error)
end
it 'logs and saves error if there is an exception' do
error_message = 'error message'
allow(service).to receive(:repository).and_raise("error message")
allow(service).to receive(:execute_hooks)
service.execute(merge_request)
expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message))
end
it 'logs and saves error if there is an PreReceiveError exception' do
error_message = 'error message'
allow(service).to receive(:repository).and_raise(GitHooksService::PreReceiveError, error_message)
allow(service).to receive(:execute_hooks)
service.execute(merge_request)
expect(merge_request.merge_error).to include(error_message)
expect(Rails.logger).to have_received(:error).with(a_string_matching(error_message))
end
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