Commit cd803a62 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'reduce-diff-in-pipeline_trigger_service' into 'master'

[EE] Reduce diff with CE in Ci::PipelineTriggerService

See merge request gitlab-org/gitlab-ee!9394
parents 8850e61c 08d47ff7
......@@ -31,41 +31,18 @@ module Ci
end
end
def create_pipeline_from_job(job)
# this check is to not leak the presence of the project if user cannot read it
return unless can?(job.user, :read_project, project)
return error("400 Job has to be running", 400) unless job.running?
pipeline = Ci::CreatePipelineService.new(project, job.user, ref: params[:ref])
.execute(:pipeline, ignore_skip_ci: true) do |pipeline|
source = job.sourced_pipelines.build(
source_pipeline: job.pipeline,
source_project: job.project,
pipeline: pipeline,
project: project)
pipeline.source_pipeline = source
pipeline.variables.build(variables)
end
if pipeline.persisted?
success(pipeline: pipeline)
else
error(pipeline.errors.messages, 400)
end
end
def trigger_from_token
strong_memoize(:trigger) do
Ci::Trigger.find_by_token(params[:token].to_s)
end
end
def create_pipeline_from_job(job)
# overriden in EE
end
def job_from_token
strong_memoize(:job) do
Ci::Build.find_by_token(params[:token].to_s)
end
# overriden in EE
end
def variables
......@@ -75,3 +52,5 @@ module Ci
end
end
end
Ci::PipelineTriggerService.prepend(EE::Ci::PipelineTriggerService)
# frozen_string_literal: true
module EE
module Ci
module PipelineTriggerService
extend ::Gitlab::Utils::Override
include ::Gitlab::Utils::StrongMemoize
private
override :create_pipeline_from_job
def create_pipeline_from_job(job)
# this check is to not leak the presence of the project if user cannot read it
return unless can?(job.user, :read_project, project)
return error("400 Job has to be running", 400) unless job.running?
pipeline = ::Ci::CreatePipelineService.new(project, job.user, ref: params[:ref])
.execute(:pipeline, ignore_skip_ci: true) do |pipeline|
source = job.sourced_pipelines.build(
source_pipeline: job.pipeline,
source_project: job.project,
pipeline: pipeline,
project: project)
pipeline.source_pipeline = source
pipeline.variables.build(variables)
end
if pipeline.persisted?
success(pipeline: pipeline)
else
error(pipeline.errors.messages, 400)
end
end
override :job_from_token
def job_from_token
strong_memoize(:job) do
::Ci::Build.find_by_token(params[:token].to_s)
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment