debian-mirror-gitlab/lib/gitlab/ci/pipeline/seed/build.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
module Gitlab
module Ci
module Pipeline
module Seed
class Build < Seed::Base
include Gitlab::Utils::StrongMemoize
delegate :dig, to: :@attributes
def initialize(pipeline, attributes)
@pipeline = pipeline
@attributes = attributes
@only = Gitlab::Ci::Build::Policy
.fabricate(attributes.delete(:only))
@except = Gitlab::Ci::Build::Policy
.fabricate(attributes.delete(:except))
end
def included?
strong_memoize(:inclusion) do
@only.all? { |spec| spec.satisfied_by?(@pipeline, self) } &&
@except.none? { |spec| spec.satisfied_by?(@pipeline, self) }
end
end
def attributes
@attributes.merge(
pipeline: @pipeline,
project: @pipeline.project,
user: @pipeline.user,
ref: @pipeline.ref,
tag: @pipeline.tag,
trigger_request: @pipeline.legacy_trigger,
protected: @pipeline.protected_ref?
)
end
2019-03-02 22:35:43 +05:30
def bridge?
@attributes.to_h.dig(:options, :trigger).present?
end
2018-05-09 12:01:36 +05:30
def to_resource
strong_memoize(:resource) do
2019-03-02 22:35:43 +05:30
if bridge?
::Ci::Bridge.new(attributes)
else
::Ci::Build.new(attributes)
end
2018-05-09 12:01:36 +05:30
end
end
end
end
end
end
end