gitlab-org--gitlab-foss/app/services/merge_requests/rebase_service.rb

44 lines
1,016 B
Ruby

# frozen_string_literal: true
module MergeRequests
class RebaseService < MergeRequests::BaseService
REBASE_ERROR = 'Rebase failed. Please rebase locally'
attr_reader :merge_request, :rebase_error
def execute(merge_request, skip_ci: false)
@merge_request = merge_request
@skip_ci = skip_ci
if rebase
success
else
error(rebase_error)
end
end
def rebase
repository.rebase(current_user, merge_request, skip_ci: @skip_ci)
true
rescue StandardError => e
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