debian-mirror-gitlab/lib/gitlab/ci/pipeline/seed/processable/resource_group.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

49 lines
1.4 KiB
Ruby
Raw Normal View History

2020-03-13 15:44:24 +05:30
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Seed
2021-03-11 19:13:27 +05:30
module Processable
2020-03-13 15:44:24 +05:30
class ResourceGroup < Seed::Base
include Gitlab::Utils::StrongMemoize
2021-03-11 19:13:27 +05:30
attr_reader :processable, :resource_group_key
2020-03-13 15:44:24 +05:30
2021-03-11 19:13:27 +05:30
def initialize(processable, resource_group_key)
@processable = processable
2020-03-13 15:44:24 +05:30
@resource_group_key = resource_group_key
end
def to_resource
return unless resource_group_key.present?
2021-03-11 19:13:27 +05:30
resource_group = processable.project.resource_groups
2020-03-13 15:44:24 +05:30
.safe_find_or_create_by(key: expanded_resource_group_key)
resource_group if resource_group.persisted?
end
private
def expanded_resource_group_key
strong_memoize(:expanded_resource_group_key) do
2021-11-11 11:23:49 +05:30
ExpandVariables.expand(resource_group_key, -> { variables })
end
end
def variables
processable.simple_variables.tap do |variables|
# Adding persisted environment variables
if processable.persisted_environment.present?
variables.concat(processable.persisted_environment.predefined_variables)
end
2020-03-13 15:44:24 +05:30
end
end
end
end
end
end
end
end