diff options
-rw-r--r-- | app/models/ci/pipeline.rb | 8 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/base.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/build.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/stage.rb | 37 |
4 files changed, 36 insertions, 30 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 2e8d7f9dbfe..8889195ec24 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -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 diff --git a/lib/gitlab/ci/pipeline/seed/base.rb b/lib/gitlab/ci/pipeline/seed/base.rb index 44c85aa6716..6af3f5e5603 100644 --- a/lib/gitlab/ci/pipeline/seed/base.rb +++ b/lib/gitlab/ci/pipeline/seed/base.rb @@ -10,6 +10,10 @@ module Gitlab def excluded? raise NotImplementedError end + + def to_resource + raise NotImplementedError + end end end end diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index f5dbb3a1c40..f49dbb2f0ba 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -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 diff --git a/lib/gitlab/ci/pipeline/seed/stage.rb b/lib/gitlab/ci/pipeline/seed/stage.rb index 3665794f354..3e5abf8c02b 100644 --- a/lib/gitlab/ci/pipeline/seed/stage.rb +++ b/lib/gitlab/ci/pipeline/seed/stage.rb @@ -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 |