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

dag.rb « yaml_processor « ci « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ad78277080b69afc02a433a59d373fbe8499f1f8 (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
# frozen_string_literal: true

# Represents Dag pipeline
module Gitlab
  module Ci
    class YamlProcessor
      class Dag
        include TSort

        def initialize(nodes)
          @nodes = nodes
        end

        def self.order(jobs)
          new(jobs).tsort
        end

        def self.check_circular_dependencies!(jobs)
          new(jobs).tsort
        rescue TSort::Cyclic
          raise ValidationError, 'The pipeline has circular dependencies'
        end

        def tsort_each_child(node, &block)
          return unless @nodes[node]

          raise TSort::Cyclic, /topological sort failed/ if @nodes[node].include?(node)

          @nodes[node].each(&block)
        end

        def tsort_each_node(&block)
          @nodes.each_key(&block)
        end
      end
    end
  end
end