summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/chain/populate.rb
blob: 5368ff154812e0f9e2634476a865442659ba0f7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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