Welcome to mirror list, hosted at ThFree Co, Russian Federation.

environment.rb « seed « pipeline « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8353bc523bf2f75d2b860e0defaae51aba965307 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Seed
        class Environment < Seed::Base
          attr_reader :job, :merge_request

          delegate :simple_variables, to: :job

          def initialize(job, merge_request: nil)
            @job = job
            @merge_request = merge_request
          end

          def to_resource
            environments.safe_find_or_create_by(name: expanded_environment_name) do |environment|
              # Initialize the attributes at creation
              environment.auto_stop_in = expanded_auto_stop_in
              environment.tier = deployment_tier
              environment.merge_request = merge_request
            end
          end

          private

          def environments
            job.project.environments
          end

          def auto_stop_in
            job.environment_auto_stop_in
          end

          def deployment_tier
            job.environment_tier_from_options
          end

          def expanded_environment_name
            job.expanded_environment_name
          end

          def expanded_auto_stop_in
            return unless auto_stop_in

            ExpandVariables.expand(auto_stop_in, -> { simple_variables.sort_and_expand_all })
          end
        end
      end
    end
  end
end