Commit ad61a181 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Support building all pipeline resource before saving

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