diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-02 15:48:25 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-11-02 15:48:25 +0100 |
commit | a8da5238474f8f7ad4dab5461c5c5605894535db (patch) | |
tree | b95a182fcdaf813d1bd11c304449bbc60a891f71 | |
parent | 8a6a312db8148433fca78da0b5c9db8f966e16fc (diff) | |
download | gitlab-ce-a8da5238474f8f7ad4dab5461c5c5605894535db.tar.gz |
Refactor Gitlab::Ci::Config::Normalizer
-rw-r--r-- | lib/gitlab/ci/config/normalizer.rb | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/lib/gitlab/ci/config/normalizer.rb b/lib/gitlab/ci/config/normalizer.rb index 2dc408ac392..43331b28e2b 100644 --- a/lib/gitlab/ci/config/normalizer.rb +++ b/lib/gitlab/ci/config/normalizer.rb @@ -6,6 +6,13 @@ module Gitlab class Normalizer class << self 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_config = jobs_config.map do |name, config| @@ -19,29 +26,32 @@ module Gitlab end end.reduce(:merge) - parallelized_config.each do |name, config| - next unless config[:dependencies] - - deps = config[:dependencies].map do |dep| - if parallelized_jobs.keys.include?(dep.to_sym) - config[:dependencies].delete(dep) - parallelized_jobs[dep.to_sym] - else - dep - end - end.flatten - - config[:dependencies] = deps - end + [parallelized_config, parallelized_jobs] end - private + def parallelize_dependencies(jobs_config, parallelized_jobs) + jobs_config.map do |name, config| + if config[:dependencies] + deps = config[:dependencies].map do |dep| + if parallelized_jobs.keys.include?(dep.to_sym) + parallelized_jobs[dep.to_sym] + else + dep + end + end.flatten + + { name => config.merge(dependencies: deps) } + else + { name => config } + end + end.reduce(:merge) + end def parallelize_job_names(name, total) jobs = [] - total.times do |idx| - jobs << ["#{name} #{idx + 1}/#{total}", idx + 1] + 1.upto(total) do |idx| + jobs << ["#{name} #{idx}/#{total}", idx] end jobs |