Commit a8da5238 authored by Matija Čupić's avatar Matija Čupić

Refactor Gitlab::Ci::Config::Normalizer

parent 8a6a312d
...@@ -6,6 +6,13 @@ module Gitlab ...@@ -6,6 +6,13 @@ module Gitlab
class Normalizer class Normalizer
class << self class << self
def normalize_jobs(jobs_config) def normalize_jobs(jobs_config)
parallelized_config, parallelized_jobs = parallelize_jobs(jobs_config)
parallelize_dependencies(parallelized_config, parallelized_jobs)
end
private
def parallelize_jobs(jobs_config)
parallelized_jobs = {} parallelized_jobs = {}
parallelized_config = jobs_config.map do |name, config| parallelized_config = jobs_config.map do |name, config|
...@@ -19,29 +26,32 @@ module Gitlab ...@@ -19,29 +26,32 @@ module Gitlab
end end
end.reduce(:merge) end.reduce(:merge)
parallelized_config.each do |name, config| [parallelized_config, parallelized_jobs]
next unless config[:dependencies] end
def parallelize_dependencies(jobs_config, parallelized_jobs)
jobs_config.map do |name, config|
if config[:dependencies]
deps = config[:dependencies].map do |dep| deps = config[:dependencies].map do |dep|
if parallelized_jobs.keys.include?(dep.to_sym) if parallelized_jobs.keys.include?(dep.to_sym)
config[:dependencies].delete(dep)
parallelized_jobs[dep.to_sym] parallelized_jobs[dep.to_sym]
else else
dep dep
end end
end.flatten end.flatten
config[:dependencies] = deps { name => config.merge(dependencies: deps) }
else
{ name => config }
end end
end.reduce(:merge)
end end
private
def parallelize_job_names(name, total) def parallelize_job_names(name, total)
jobs = [] jobs = []
total.times do |idx| 1.upto(total) do |idx|
jobs << ["#{name} #{idx + 1}/#{total}", idx + 1] jobs << ["#{name} #{idx}/#{total}", idx]
end end
jobs jobs
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment