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

stage.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: c3e9452963452c4aeb3e7a5cecc3495d0f08ce7f (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
54
55
56
57
58
59
60
# frozen_string_literal: true

module Gitlab
  module Ci
    module Pipeline
      module Seed
        class Stage < Seed::Base
          include Gitlab::Utils::StrongMemoize

          delegate :size, to: :seeds
          delegate :dig, to: :seeds

          attr_reader :attributes

          def initialize(context, stage_attributes, previous_stages)
            pipeline = context.pipeline
            @attributes = {
              name: stage_attributes.fetch(:name),
              position: stage_attributes.fetch(:index),
              pipeline: pipeline,
              project: pipeline.project,
              partition_id: pipeline.partition_id
            }

            @stage = ::Ci::Stage.new(@attributes)

            @builds = stage_attributes.fetch(:builds).map do |build_attributes|
              Seed::Build.new(context, build_attributes, previous_stages + [self], @stage)
            end
          end

          def seeds
            @builds.select(&:included?)
          end
          strong_memoize_attr :seeds

          def errors
            @builds.flat_map(&:errors).compact
          end
          strong_memoize_attr :errors

          def seeds_names
            seeds.map(&:name).to_set
          end
          strong_memoize_attr :seeds_names

          def included?
            seeds.any?
          end

          def to_resource
            @stage.statuses = seeds.map(&:to_resource)
            @stage
          end
          strong_memoize_attr :to_resource
        end
      end
    end
  end
end