build.rb 1.3 KB
Newer Older
G
Grzegorz Bizon 已提交
1 2 3 4 5
module Gitlab
  module Ci
    module Pipeline
      module Seed
        class Build < Seed::Base
6 7
          include Gitlab::Utils::StrongMemoize

8
          delegate :dig, to: :@attributes
9

G
Grzegorz Bizon 已提交
10 11 12
          def initialize(pipeline, attributes)
            @pipeline = pipeline
            @attributes = attributes
13

14 15 16 17
            @only = Gitlab::Ci::Build::Policy
              .fabricate(attributes.delete(:only))
            @except = Gitlab::Ci::Build::Policy
              .fabricate(attributes.delete(:except))
G
Grzegorz Bizon 已提交
18 19
          end

20 21
          def included?
            strong_memoize(:inclusion) do
22 23
              @only.all? { |spec| spec.satisfied_by?(@pipeline, self) } &&
                @except.none? { |spec| spec.satisfied_by?(@pipeline, self) }
24 25 26
            end
          end

G
Grzegorz Bizon 已提交
27
          def attributes
28 29 30
            @attributes.merge(
              pipeline: @pipeline,
              project: @pipeline.project,
31
              user: @pipeline.user,
32 33 34 35 36 37 38 39
              ref: @pipeline.ref,
              tag: @pipeline.tag,
              trigger_request: @pipeline.legacy_trigger,
              protected: @pipeline.protected_ref?
            )
          end

          def to_resource
40 41 42
            strong_memoize(:resource) do
              ::Ci::Build.new(attributes)
            end
G
Grzegorz Bizon 已提交
43 44 45 46 47 48
          end
        end
      end
    end
  end
end