2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module MergeRequests
|
2019-12-26 22:10:19 +05:30
|
|
|
class RebaseService < MergeRequests::BaseService
|
2019-12-04 20:38:33 +05:30
|
|
|
REBASE_ERROR = 'Rebase failed. Please rebase locally'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
attr_reader :merge_request
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def execute(merge_request, skip_ci: false)
|
2018-03-17 18:26:18 +05:30
|
|
|
@merge_request = merge_request
|
2020-03-13 15:44:24 +05:30
|
|
|
@skip_ci = skip_ci
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
if rebase
|
|
|
|
success
|
|
|
|
else
|
|
|
|
error(REBASE_ERROR)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def rebase
|
2019-10-12 21:52:04 +05:30
|
|
|
# Ensure Gitaly isn't already running a rebase
|
|
|
|
if source_project.repository.rebase_in_progress?(merge_request.id)
|
2020-05-24 23:13:21 +05:30
|
|
|
log_error(exception: nil, message: 'Rebase task canceled: Another rebase is already in progress', save_message_on_model: true)
|
2018-03-17 18:26:18 +05:30
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
repository.rebase(current_user, merge_request, skip_ci: @skip_ci)
|
2018-11-08 19:23:39 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
true
|
2021-06-08 01:23:25 +05:30
|
|
|
rescue StandardError => e
|
2020-05-24 23:13:21 +05:30
|
|
|
log_error(exception: e, message: REBASE_ERROR, save_message_on_model: true)
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
false
|
2019-09-30 21:07:59 +05:30
|
|
|
ensure
|
|
|
|
merge_request.update_column(:rebase_jid, nil)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|