2019-12-21 20:55:43 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Pipeline
|
|
|
|
module Seed
|
|
|
|
class Environment < Seed::Base
|
2022-10-11 01:57:18 +05:30
|
|
|
attr_reader :job, :merge_request
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
delegate :simple_variables, to: :job
|
|
|
|
|
|
|
|
def initialize(job, merge_request: nil)
|
2019-12-21 20:55:43 +05:30
|
|
|
@job = job
|
2022-10-11 01:57:18 +05:30
|
|
|
@merge_request = merge_request
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def to_resource
|
2021-01-29 00:20:46 +05:30
|
|
|
environments.safe_find_or_create_by(name: expanded_environment_name) do |environment|
|
2021-04-17 20:07:23 +05:30
|
|
|
# Initialize the attributes at creation
|
2022-10-11 01:57:18 +05:30
|
|
|
environment.auto_stop_in = expanded_auto_stop_in
|
2021-04-17 20:07:23 +05:30
|
|
|
environment.tier = deployment_tier
|
2022-10-11 01:57:18 +05:30
|
|
|
environment.merge_request = merge_request
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-01-29 00:20:46 +05:30
|
|
|
def environments
|
|
|
|
job.project.environments
|
|
|
|
end
|
|
|
|
|
|
|
|
def auto_stop_in
|
2021-02-22 17:27:13 +05:30
|
|
|
job.environment_auto_stop_in
|
2021-01-29 00:20:46 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
def deployment_tier
|
2022-08-27 11:52:29 +05:30
|
|
|
job.environment_tier_from_options
|
2021-04-17 20:07:23 +05:30
|
|
|
end
|
|
|
|
|
2019-12-21 20:55:43 +05:30
|
|
|
def expanded_environment_name
|
|
|
|
job.expanded_environment_name
|
|
|
|
end
|
2022-10-11 01:57:18 +05:30
|
|
|
|
|
|
|
def expanded_auto_stop_in
|
|
|
|
return unless auto_stop_in
|
|
|
|
|
|
|
|
ExpandVariables.expand(auto_stop_in, -> { simple_variables.sort_and_expand_all })
|
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|