2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
module MergeRequests
|
2019-11-15 13:06:24 -05:00
|
|
|
class RebaseService < MergeRequests::BaseService
|
2019-08-31 15:22:19 -04:00
|
|
|
REBASE_ERROR = 'Rebase failed. Please rebase locally'
|
2018-01-09 10:49:39 -05:00
|
|
|
|
2019-11-15 13:06:24 -05:00
|
|
|
attr_reader :merge_request
|
|
|
|
|
2020-01-16 16:08:24 -05:00
|
|
|
def execute(merge_request, skip_ci: false)
|
2017-12-20 04:01:21 -05:00
|
|
|
@merge_request = merge_request
|
2020-01-16 16:08:24 -05:00
|
|
|
@skip_ci = skip_ci
|
2017-12-20 04:01:21 -05:00
|
|
|
|
|
|
|
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
|
2019-08-15 14:54:08 -04:00
|
|
|
# Ensure Gitaly isn't already running a rebase
|
|
|
|
if source_project.repository.rebase_in_progress?(merge_request.id)
|
2020-05-07 11:09:29 -04:00
|
|
|
log_error(exception: nil, message: 'Rebase task canceled: Another rebase is already in progress', save_message_on_model: true)
|
2017-12-20 04:01:21 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2020-01-16 16:08:24 -05:00
|
|
|
repository.rebase(current_user, merge_request, skip_ci: @skip_ci)
|
2018-06-27 05:47:30 -04:00
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
true
|
|
|
|
rescue => e
|
2020-05-07 11:09:29 -04:00
|
|
|
log_error(exception: e, message: REBASE_ERROR, save_message_on_model: true)
|
|
|
|
|
2017-12-20 04:01:21 -05:00
|
|
|
false
|
2019-06-21 12:56:47 -04:00
|
|
|
ensure
|
|
|
|
merge_request.update_column(:rebase_jid, nil)
|
2017-12-20 04:01:21 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|