2018-10-26 04:12:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-03 12:20:34 +00:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
2018-09-07 18:53:28 +00:00
|
|
|
#
|
2016-06-09 11:01:19 +00:00
|
|
|
# Base GitLab CI Configuration facade
|
|
|
|
#
|
2016-06-03 12:20:34 +00:00
|
|
|
class Config
|
2018-08-17 13:04:58 +00:00
|
|
|
ConfigError = Class.new(StandardError)
|
|
|
|
|
2018-09-07 20:03:05 +00:00
|
|
|
def initialize(config, opts = {})
|
2018-09-11 14:29:48 +00:00
|
|
|
@config = Config::Extendable
|
|
|
|
.new(build_config(config, opts))
|
|
|
|
.to_hash
|
2018-09-08 12:55:36 +00:00
|
|
|
|
2018-09-11 14:29:48 +00:00
|
|
|
@global = Entry::Global.new(@config)
|
|
|
|
@global.compose!
|
2018-10-18 09:06:32 +00:00
|
|
|
rescue Loader::FormatError,
|
|
|
|
Extendable::ExtensionError,
|
|
|
|
External::Processor::IncludeError => e
|
2018-09-11 14:29:48 +00:00
|
|
|
raise Config::ConfigError, e.message
|
2016-06-03 12:20:34 +00:00
|
|
|
end
|
|
|
|
|
2016-06-09 12:48:40 +00:00
|
|
|
def valid?
|
2016-06-16 12:16:33 +00:00
|
|
|
@global.valid?
|
2016-06-09 12:48:40 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
2016-06-16 12:16:33 +00:00
|
|
|
@global.errors
|
2016-06-09 12:48:40 +00:00
|
|
|
end
|
|
|
|
|
2016-06-03 12:20:34 +00:00
|
|
|
def to_hash
|
|
|
|
@config
|
|
|
|
end
|
2016-11-18 13:30:27 +00:00
|
|
|
|
|
|
|
##
|
|
|
|
# Temporary method that should be removed after refactoring
|
|
|
|
#
|
|
|
|
def before_script
|
|
|
|
@global.before_script_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
|
|
|
@global.image_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def services
|
|
|
|
@global.services_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def after_script
|
|
|
|
@global.after_script_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def variables
|
|
|
|
@global.variables_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def stages
|
|
|
|
@global.stages_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache
|
|
|
|
@global.cache_value
|
|
|
|
end
|
|
|
|
|
|
|
|
def jobs
|
|
|
|
@global.jobs_value
|
|
|
|
end
|
2018-08-17 13:04:58 +00:00
|
|
|
|
2018-09-08 12:55:36 +00:00
|
|
|
private
|
|
|
|
|
2018-09-07 20:03:05 +00:00
|
|
|
def build_config(config, opts = {})
|
2018-09-07 19:33:06 +00:00
|
|
|
initial_config = Loader.new(config).load!
|
2018-09-07 20:03:05 +00:00
|
|
|
project = opts.fetch(:project, nil)
|
2018-09-07 19:33:06 +00:00
|
|
|
|
2018-09-07 20:03:05 +00:00
|
|
|
if project
|
|
|
|
process_external_files(initial_config, project, opts)
|
2018-09-07 19:33:06 +00:00
|
|
|
else
|
|
|
|
initial_config
|
|
|
|
end
|
2018-08-17 13:04:58 +00:00
|
|
|
end
|
2018-09-07 20:03:05 +00:00
|
|
|
|
|
|
|
def process_external_files(config, project, opts)
|
2018-09-08 12:55:36 +00:00
|
|
|
sha = opts.fetch(:sha) { project.repository.root_ref_sha }
|
2018-10-16 13:09:36 +00:00
|
|
|
Config::External::Processor.new(config, project, sha).perform
|
2018-09-07 20:03:05 +00:00
|
|
|
end
|
2016-06-03 12:20:34 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|