debian-mirror-gitlab/app/services/merge_requests/merge_base_service.rb

77 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# 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)
# No-op
end
def source
2019-12-26 22:10:19 +05:30
strong_memoize(:source) do
2020-07-28 23:09:34 +05:30
if merge_request.squash_on_merge?
2019-12-26 22:10:19 +05:30
squash_sha!
else
merge_request.diff_head_sha
end
2019-07-07 11:18:12 +05:30
end
end
private
2019-09-30 21:07:59 +05:30
def check_source
unless source
raise_error('No source for merge')
end
end
# Overridden in EE.
def check_size_limit
# No-op
end
2019-07-07 11:18:12 +05:30
# Overridden in EE.
def error_check!
# No-op
end
def raise_error(message)
raise MergeError, message
end
def handle_merge_error(*args)
# No-op
end
def commit_message
params[:commit_message] ||
2022-03-02 08:16:31 +05:30
merge_request.default_merge_commit_message(user: current_user)
2019-07-07 11:18:12 +05:30
end
def squash_sha!
2019-12-26 22:10:19 +05:30
params[:merge_request] = merge_request
2021-06-08 01:23:25 +05:30
squash_result = ::MergeRequests::SquashService.new(project: project, current_user: current_user, params: params).execute
2019-12-26 22:10:19 +05:30
case squash_result[:status]
when :success
squash_result[:squash_sha]
when :error
raise ::MergeRequests::MergeService::MergeError, squash_result[:message]
2019-07-07 11:18:12 +05:30
end
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
MergeRequests::MergeBaseService.prepend_mod_with('MergeRequests::MergeBaseService')