build.rb 929 Bytes
Newer Older
1 2 3 4 5
module Gitlab
  module Ci
    module Pipeline
      module Seed
        class Build < Seed::Base
6 7 8 9
          attr_reader :pipeline, :attributes

          delegate :dig, to: :attributes

10 11 12 13 14 15 16 17 18 19 20 21
          def initialize(pipeline, attributes)
            @pipeline = pipeline
            @attributes = attributes
          end

          # TODO find a different solution
          #
          def user=(current_user)
            @attributes.merge!(user: current_user)
          end

          def attributes
22 23 24 25 26 27 28 29 30 31 32 33
            @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)
34 35 36 37 38 39
          end
        end
      end
    end
  end
end