Commit 91a67a79 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Simplify cross-pipeline creation service

parent 6262b3b5
......@@ -6,7 +6,7 @@ module Ci
self.table_name = "ci_sources_pipelines"
belongs_to :project, class_name: Project
belongs_to :pipeline, class_name: Ci::Pipeline
belongs_to :pipeline, class_name: Ci::Pipeline, inverse_of: :source_pipeline
belongs_to :source_project, class_name: Project, foreign_key: :source_project_id
belongs_to :source_job, class_name: CommitStatus, foreign_key: :source_job_id
......
......@@ -19,7 +19,7 @@ module EE
has_many :vulnerabilities_occurrence_pipelines, class_name: 'Vulnerabilities::OccurrencePipeline'
has_many :vulnerabilities, source: :occurrence, through: :vulnerabilities_occurrence_pipelines, class_name: 'Vulnerabilities::Occurrence'
has_one :source_pipeline, class_name: ::Ci::Sources::Pipeline
has_one :source_pipeline, class_name: ::Ci::Sources::Pipeline, inverse_of: :pipeline
has_many :sourced_pipelines, class_name: ::Ci::Sources::Pipeline, foreign_key: :source_pipeline_id
has_one :triggered_by_pipeline, through: :source_pipeline, source: :source_pipeline
......
......@@ -19,15 +19,7 @@ module Ci
return bridge.drop!(:insufficient_bridge_permissions)
end
create_pipeline do |pipeline|
source = bridge.sourced_pipelines.build(
source_pipeline: bridge.pipeline,
source_project: bridge.project,
project: target_project,
pipeline: pipeline)
pipeline.source_pipeline = source
end
create_pipeline!
end
private
......@@ -42,11 +34,15 @@ module Ci
can?(target_user, :create_pipeline, target_project)
end
def create_pipeline
def create_pipeline!
::Ci::CreatePipelineService
.new(target_project, target_user, ref: target_ref)
.execute(:pipeline, ignore_skip_ci: true) do |pipeline|
yield pipeline
@bridge.sourced_pipelines.build(
source_pipeline: @bridge.pipeline,
source_project: @bridge.project,
project: target_project,
pipeline: pipeline)
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