summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/chain/populate.rb
blob: 94d9b44b2571db5b8b08d6221921a638bd60183c (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
33
34
35
36
37
38
module Gitlab
  module Ci
    module Pipeline
      module Chain
        class Populate < Chain::Base
          include Chain::Helpers

          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

            if pipeline.invalid?
              error('Failed to build the pipeline!')
            end

            raise Populate::PopulateError if pipeline.persisted?
          end

          def break?
            pipeline.invalid?
          end
        end
      end
    end
  end
end