Welcome to mirror list, hosted at ThFree Co, Russian Federation.

seed.rb « stage « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e19aae35a81c5709944c8a9be079ccd960830b9b (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Gitlab
  module Ci
    module Stage
      class Seed
        attr_reader :pipeline
        delegate :project, to: :pipeline

        def initialize(pipeline, stage, jobs)
          @pipeline = pipeline
          @stage = { name: stage }
          @jobs = jobs.to_a.dup
        end

        def user=(current_user)
          @jobs.map! do |attributes|
            attributes.merge(user: current_user)
          end
        end

        def stage
          @stage.merge(project: project)
        end

        def builds
          trigger = pipeline.trigger_requests.first

          @jobs.map do |attributes|
            attributes.merge(project: project,
                             ref: pipeline.ref,
                             tag: pipeline.tag,
                             trigger_request: trigger,
                             protected: protected_ref?)
          end
        end

        def create!
          pipeline.stages.create!(stage).tap do |stage|
            builds_attributes = builds.map do |attributes|
              attributes.merge(stage_id: stage.id)
            end

            pipeline.builds.create!(builds_attributes).each do |build|
              yield build if block_given?
            end
          end
        end

        private

        def protected_ref?
          @protected_ref ||= project.protected_for?(pipeline.ref)
        end
      end
    end
  end
end