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-03-11 19:13:27 +05:30
|
|
|
ExpandVariables.expand(resource_group_key, -> { processable.simple_variables })
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|