2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
module MergeRequests
|
|
|
|
class RebaseService < MergeRequests::WorkingCopyBaseService
|
2018-01-09 10:49:39 -05:00
|
|
|
REBASE_ERROR = 'Rebase failed. Please rebase locally'.freeze
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
def execute(merge_request)
|
|
|
|
@merge_request = merge_request
|
|
|
|
|
|
|
|
if rebase
|
|
|
|
success
|
|
|
|
else
|
2018-01-09 10:49:39 -05:00
|
|
|
error(REBASE_ERROR)
|
2017-12-20 04:01:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebase
|
|
|
|
if merge_request.rebase_in_progress?
|
|
|
|
log_error('Rebase task canceled: Another rebase is already in progress', save_message_on_model: true)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2018-06-27 05:47:30 -04:00
|
|
|
log_prefix = "#{self.class.name} info (#{merge_request.to_reference(full: true)}):"
|
|
|
|
|
|
|
|
Gitlab::GitLogger.info("#{log_prefix} rebase started")
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
rebase_sha = repository.rebase(current_user, merge_request)
|
|
|
|
|
2018-06-27 05:47:30 -04:00
|
|
|
Gitlab::GitLogger.info("#{log_prefix} rebased to #{rebase_sha}")
|
|
|
|
|
2018-07-02 06:43:06 -04:00
|
|
|
merge_request.update(rebase_commit_sha: rebase_sha)
|
2017-12-20 04:01:21 -05:00
|
|
|
|
2018-06-27 05:47:30 -04:00
|
|
|
Gitlab::GitLogger.info("#{log_prefix} rebase SHA saved: #{rebase_sha}")
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
true
|
|
|
|
rescue => e
|
2018-01-09 10:49:39 -05:00
|
|
|
log_error(REBASE_ERROR, save_message_on_model: true)
|
|
|
|
log_error(e.message)
|
2017-12-20 04:01:21 -05:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|