Commit 67249980 authored by Stan Hu's avatar Stan Hu

Show rebase pre-receive error to user

If a project has a push rule configured, a rebase may fail quietly with
the message, "Rebase failed. Please rebase locally. Please try again."
The user has no idea why this rebase failed.

Since pre-receive messages are sanitized to show only text that starts
with "GitLab:", we can safely display these to the user in
`RebaseService`, just as we do in `MergeService`.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/213608
parent 035adf72
......@@ -4,7 +4,7 @@ module MergeRequests
class RebaseService < MergeRequests::BaseService
REBASE_ERROR = 'Rebase failed. Please rebase locally'
attr_reader :merge_request
attr_reader :merge_request, :rebase_error
def execute(merge_request, skip_ci: false)
@merge_request = merge_request
......@@ -13,7 +13,7 @@ module MergeRequests
if rebase
success
else
error(REBASE_ERROR)
error(rebase_error)
end
end
......@@ -22,11 +22,23 @@ module MergeRequests
true
rescue StandardError => e
log_error(exception: e, message: REBASE_ERROR, save_message_on_model: true)
set_rebase_error(e)
log_error(exception: e, message: rebase_error, save_message_on_model: true)
false
ensure
merge_request.update_column(:rebase_jid, nil)
end
private
def set_rebase_error(exception)
@rebase_error =
if exception.is_a?(Gitlab::Git::PreReceiveError)
"Something went wrong during the rebase pre-receive hook: #{exception.message}."
else
REBASE_ERROR
end
end
end
end
......@@ -80,6 +80,27 @@ RSpec.describe MergeRequests::RebaseService do
end
end
context 'with a pre-receive failure' do
let(:pre_receive_error) { "Commit message does not follow the pattern 'ACME'" }
let(:merge_error) { "Something went wrong during the rebase pre-receive hook: #{pre_receive_error}." }
before do
allow(repository).to receive(:gitaly_operation_client).and_raise(Gitlab::Git::PreReceiveError, "GitLab: #{pre_receive_error}")
end
it 'saves a specific message' do
subject.execute(merge_request)
expect(merge_request.reload.merge_error).to eq merge_error
end
it 'returns an error' do
expect(service.execute(merge_request)).to match(
status: :error,
message: merge_error)
end
end
context 'with git command failure' do
before do
allow(repository).to receive(:gitaly_operation_client).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong')
......
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