summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/stage/seed.rb
blob: 95237bff5d71a5e8aa7629a6d795051038282616 (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 Stage
      class Seed
        attr_reader :name, :builds

        def initialize(name:, builds:)
          @name = name
          @builds = builds
        end

        def pipeline=(pipeline)
          trigger_request = pipeline.trigger_requests.first

          @builds.each do |attributes|
            attributes.merge!(
              pipeline: pipeline,
              project: pipeline.project,
              ref: pipeline.ref,
              tag: pipeline.tag,
              trigger_request: trigger_request
            )
          end
        end

        def user=(current_user)
          @builds.each do |attributes|
            attributes.merge!(user: current_user)
          end
        end

        def to_attributes
          { name: @name, builds_attributes: @builds }
        end
      end
    end
  end
end