2019-01-31 13:32:44 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MergeRequests
|
|
|
|
class MergeBaseService < MergeRequests::BaseService
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
MergeError = Class.new(StandardError)
|
|
|
|
|
|
|
|
attr_reader :merge_request
|
|
|
|
|
|
|
|
# Overridden in EE.
|
|
|
|
def hooks_validation_pass?(_merge_request)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
# Overridden in EE.
|
|
|
|
def hooks_validation_error(_merge_request)
|
2019-02-12 16:57:57 -05:00
|
|
|
# No-op
|
2019-01-31 13:32:44 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def source
|
2019-11-15 10:06:12 -05:00
|
|
|
strong_memoize(:source) do
|
|
|
|
if merge_request.squash
|
|
|
|
squash_sha!
|
|
|
|
else
|
|
|
|
merge_request.diff_head_sha
|
|
|
|
end
|
2019-01-31 13:32:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-07-05 15:31:10 -04:00
|
|
|
def check_source
|
|
|
|
unless source
|
|
|
|
raise_error('No source for merge')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Overridden in EE.
|
|
|
|
def check_size_limit
|
|
|
|
# No-op
|
|
|
|
end
|
|
|
|
|
2019-02-12 16:57:57 -05:00
|
|
|
# Overridden in EE.
|
|
|
|
def error_check!
|
|
|
|
# No-op
|
|
|
|
end
|
|
|
|
|
2019-02-11 10:14:11 -05:00
|
|
|
def raise_error(message)
|
|
|
|
raise MergeError, message
|
|
|
|
end
|
|
|
|
|
2019-01-31 13:32:44 -05:00
|
|
|
def handle_merge_error(*args)
|
|
|
|
# No-op
|
|
|
|
end
|
|
|
|
|
|
|
|
def commit_message
|
|
|
|
params[:commit_message] ||
|
|
|
|
merge_request.default_merge_commit_message
|
|
|
|
end
|
|
|
|
|
|
|
|
def squash_sha!
|
2019-11-15 10:06:12 -05:00
|
|
|
params[:merge_request] = merge_request
|
|
|
|
squash_result = ::MergeRequests::SquashService.new(project, current_user, params).execute
|
|
|
|
|
|
|
|
case squash_result[:status]
|
|
|
|
when :success
|
|
|
|
squash_result[:squash_sha]
|
|
|
|
when :error
|
|
|
|
raise ::MergeRequests::MergeService::MergeError, squash_result[:message]
|
2019-01-31 13:32:44 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
|
|
|
MergeRequests::MergeBaseService.prepend_if_ee('EE::MergeRequests::MergeBaseService')
|