Commit a560f785 authored by Jan Provaznik's avatar Jan Provaznik

Store only generic message if rebase fails

Instead of storing detailed rebase error, only a generic message is
stored with MR. The reason is that this message is exposed and displayed
to end user and there is no reason to expose detailed backend
information. Error message is still logged so detailed information
can be found in logfile by admin if needed.

Related #41820
parent 678a00d6
module MergeRequests module MergeRequests
class RebaseService < MergeRequests::WorkingCopyBaseService class RebaseService < MergeRequests::WorkingCopyBaseService
REBASE_ERROR = 'Rebase failed. Please rebase locally'.freeze
def execute(merge_request) def execute(merge_request)
@merge_request = merge_request @merge_request = merge_request
if rebase if rebase
success success
else else
error('Failed to rebase. Should be done manually') error(REBASE_ERROR)
end end
end end
...@@ -22,8 +24,8 @@ module MergeRequests ...@@ -22,8 +24,8 @@ module MergeRequests
true true
rescue => e rescue => e
log_error('Failed to rebase branch:') log_error(REBASE_ERROR, save_message_on_model: true)
log_error(e.message, save_message_on_model: true) log_error(e.message)
false false
end end
end end
......
---
title: Display user friendly error message if rebase fails.
merge_request:
author:
type: fixed
...@@ -32,7 +32,7 @@ describe MergeRequests::RebaseService do ...@@ -32,7 +32,7 @@ describe MergeRequests::RebaseService do
it 'returns an error' do it 'returns an error' do
expect(service.execute(merge_request)).to match(status: :error, expect(service.execute(merge_request)).to match(status: :error,
message: 'Failed to rebase. Should be done manually') message: described_class::REBASE_ERROR)
end end
end end
...@@ -41,15 +41,15 @@ describe MergeRequests::RebaseService do ...@@ -41,15 +41,15 @@ describe MergeRequests::RebaseService do
allow(repository).to receive(:run_git!).and_raise('Something went wrong') allow(repository).to receive(:run_git!).and_raise('Something went wrong')
end end
it 'saves the error message' do it 'saves a generic error message' do
subject.execute(merge_request) subject.execute(merge_request)
expect(merge_request.reload.merge_error).to eq 'Something went wrong' expect(merge_request.reload.merge_error).to eq described_class::REBASE_ERROR
end end
it 'returns an error' do it 'returns an error' do
expect(service.execute(merge_request)).to match(status: :error, expect(service.execute(merge_request)).to match(status: :error,
message: 'Failed to rebase. Should be done manually') message: described_class::REBASE_ERROR)
end end
end end
...@@ -58,15 +58,15 @@ describe MergeRequests::RebaseService do ...@@ -58,15 +58,15 @@ describe MergeRequests::RebaseService do
allow(repository).to receive(:run_git!).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong') allow(repository).to receive(:run_git!).and_raise(Gitlab::Git::Repository::GitError, 'Something went wrong')
end end
it 'saves the error message' do it 'saves a generic error message' do
subject.execute(merge_request) subject.execute(merge_request)
expect(merge_request.reload.merge_error).to eq 'Something went wrong' expect(merge_request.reload.merge_error).to eq described_class::REBASE_ERROR
end end
it 'returns an error' do it 'returns an error' do
expect(service.execute(merge_request)).to match(status: :error, expect(service.execute(merge_request)).to match(status: :error,
message: 'Failed to rebase. Should be done manually') message: described_class::REBASE_ERROR)
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