BigW Consortium Gitlab

Commit ad61a181 by Grzegorz Bizon

Support building all pipeline resource before saving

parent ab0cd2a8
......@@ -476,17 +476,13 @@ module Ci
# TODO specs
#
def protected_ref?
strong_memoize(:protected_ref) do
project.protected_for?(ref)
end
strong_memoize(:protected_ref) { project.protected_for?(ref) }
end
# TODO specs
#
def legacy_trigger
strong_memoize(:legacy_trigger) do
trigger_requests.first
end
strong_memoize(:legacy_trigger) { trigger_requests.first }
end
def predefined_variables
......
......@@ -10,6 +10,10 @@ module Gitlab
def excluded?
raise NotImplementedError
end
def to_resource
raise NotImplementedError
end
end
end
end
......
......@@ -15,11 +15,18 @@ module Gitlab
end
def attributes
@attributes.merge(project: @pipeline.project,
ref: @pipeline.ref,
tag: @pipeline.tag,
trigger_request: @pipeline.legacy_trigger,
protected: @pipeline.protected_ref?)
@attributes.merge(
pipeline: @pipeline,
project: @pipeline.project,
ref: @pipeline.ref,
tag: @pipeline.tag,
trigger_request: @pipeline.legacy_trigger,
protected: @pipeline.protected_ref?
)
end
def to_resource
::Ci::Build.new(attributes)
end
end
end
......
......@@ -3,41 +3,45 @@ module Gitlab
module Pipeline
module Seed
class Stage < Seed::Base
attr_reader :pipeline
delegate :project, to: :pipeline
delegate :size, to: :@builds
delegate :size, to: :@seeds
def initialize(pipeline, name, builds)
@pipeline = pipeline
@name = name
@builds = builds.map do |attributes|
Seed::Build.new(pipeline, attributes)
@seeds = builds.map do |attributes|
Seed::Build.new(@pipeline, attributes)
end
end
def user=(current_user)
@builds.each { |seed| seed.user = current_user }
@seeds.each { |seed| seed.user = current_user }
end
def attributes
{ name: @name, project: project }
{ name: @name, pipeline: @pipeline, project: @pipeline.project }
end
# TODO decouple from Seed::Build
# TODO decouple
#
def builds_attributes
@builds.map(&:attributes)
@seeds.map(&:attributes)
end
def to_resource
::Ci::Stage.new(attributes)
end
def create!
pipeline.stages.build(attributes).tap do |stage|
builds_attributes.each do |build_attributes|
stage.builds.build(build_attributes).tap do |build|
build.pipeline = pipeline
to_resource.tap do |stage|
@seeds.each do |seed|
seed.to_resource.tap do |build|
stage.builds << build
end
end
@pipeline.stages << stage
stage.save!
stage.builds.each do |build|
......@@ -45,11 +49,6 @@ module Gitlab
end
end
end
private
def protected_ref?
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