BigW Consortium Gitlab

Commit e79ebabb by Grzegorz Bizon

Populate pipeline with objects before creating it

parent 6f20134d
......@@ -7,6 +7,7 @@ module Ci
Gitlab::Ci::Pipeline::Chain::Validate::Repository,
Gitlab::Ci::Pipeline::Chain::Validate::Config,
Gitlab::Ci::Pipeline::Chain::Skip,
Gitlab::Ci::Pipeline::Chain::Populate,
Gitlab::Ci::Pipeline::Chain::Create].freeze
def execute(source, ignore_skip_ci: false, save_on_errors: true, trigger_request: nil, schedule: nil, &block)
......
......@@ -16,8 +16,8 @@ module Ci
pipeline = Ci::CreatePipelineService.new(project, trigger.owner, ref: params[:ref])
.execute(:trigger, ignore_skip_ci: true) do |pipeline|
pipeline.trigger_requests.create!(trigger: trigger)
create_pipeline_variables!(pipeline)
pipeline.trigger_requests.build(trigger: trigger)
pipeline.variables.build(variables)
end
if pipeline.persisted?
......@@ -33,14 +33,10 @@ module Ci
end
end
def create_pipeline_variables!(pipeline)
return unless params[:variables]
variables = params[:variables].map do |key, value|
def variables
params[:variables].to_h.map do |key, value|
{ key: key, value: value }
end
pipeline.variables.create!(variables)
end
end
end
......@@ -9,13 +9,6 @@ module Gitlab
::Ci::Pipeline.transaction do
pipeline.save!
@command.seeds_block&.call(pipeline)
pipeline.stage_seeds.each do |seed|
seed.user = current_user
seed.to_resource.save!
end
# TODO populate environments with find_or_initialize_by in the chain too.
##
......
module Gitlab
module Ci
module Pipeline
module Chain
class Populate < Chain::Base
PopulateError = Class.new(StandardError)
def perform!
##
# Populate pipeline with seeds block.
#
# It comes from a block argument to CreatePipelineService#execute.
#
@command.seeds_block&.call(pipeline)
pipeline.stage_seeds.each do |seed|
seed.user = current_user
pipeline.stages << seed.to_resource
end
raise Populate::PopulateError if pipeline.persisted?
end
def break?
pipeline.persisted?
end
end
end
end
end
end
......@@ -37,8 +37,6 @@ module Gitlab
stage.builds << build
end
end
@pipeline.stages << stage
end
end
end
......
......@@ -79,5 +79,15 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
expect(pipeline.stages)
.to all(satisfy { |stage| stage.project.present? })
end
it 'can not be persisted without explicit pipeline assignment' do
stage = subject.to_resource
pipeline.save!
expect(stage).not_to be_persisted
expect(pipeline.reload.stages.count).to eq 0
expect(pipeline.reload.builds.count).to eq 0
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