2019-09-04 21:01:54 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module MergeRequests
|
|
|
|
class CreatePipelineService < MergeRequests::BaseService
|
|
|
|
def execute(merge_request)
|
|
|
|
return unless can_create_pipeline_for?(merge_request)
|
|
|
|
|
|
|
|
create_detached_merge_request_pipeline(merge_request)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_detached_merge_request_pipeline(merge_request)
|
|
|
|
if can_use_merge_request_ref?(merge_request)
|
|
|
|
Ci::CreatePipelineService.new(merge_request.source_project, current_user,
|
|
|
|
ref: merge_request.ref_path)
|
|
|
|
.execute(:merge_request_event, merge_request: merge_request)
|
|
|
|
else
|
|
|
|
Ci::CreatePipelineService.new(merge_request.source_project, current_user,
|
|
|
|
ref: merge_request.source_branch)
|
|
|
|
.execute(:merge_request_event, merge_request: merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_create_pipeline_for?(merge_request)
|
|
|
|
##
|
|
|
|
# UpdateMergeRequestsWorker could be retried by an exception.
|
|
|
|
# pipelines for merge request should not be recreated in such case.
|
2020-03-09 13:42:32 +05:30
|
|
|
return false if !allow_duplicate && merge_request.find_actual_head_pipeline&.merge_request?
|
2019-09-04 21:01:54 +05:30
|
|
|
return false if merge_request.has_no_commits?
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def allow_duplicate
|
|
|
|
params[:allow_duplicate]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
MergeRequests::CreatePipelineService.prepend_if_ee('EE::MergeRequests::CreatePipelineService')
|