36 lines
716 B
Ruby
36 lines
716 B
Ruby
# 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]
|
|
|
|
@nodes[node].each(&block)
|
|
end
|
|
|
|
def tsort_each_node(&block)
|
|
@nodes.each_key(&block)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|