2018-10-26 00:12:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-03 08:20:34 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
2018-09-07 14:53:28 -04:00
|
|
|
#
|
2016-06-09 07:01:19 -04:00
|
|
|
# Base GitLab CI Configuration facade
|
|
|
|
#
|
2016-06-03 08:20:34 -04:00
|
|
|
class Config
|
2018-08-17 09:04:58 -04:00
|
|
|
ConfigError = Class.new(StandardError)
|
|
|
|
|
2018-12-01 06:39:13 -05:00
|
|
|
def initialize(config, project: nil, sha: nil, user: nil)
|
2018-09-11 10:29:48 -04:00
|
|
|
@config = Config::Extendable
|
2018-12-01 06:39:13 -05:00
|
|
|
.new(build_config(config, project: project, sha: sha, user: user))
|
2018-09-11 10:29:48 -04:00
|
|
|
.to_hash
|
2018-09-08 08:55:36 -04:00
|
|
|
|
2018-09-11 10:29:48 -04:00
|
|
|
@global = Entry::Global.new(@config)
|
|
|
|
@global.compose!
|
2018-11-29 06:44:48 -05:00
|
|
|
rescue Gitlab::Config::Loader::FormatError,
|
2018-10-18 05:06:32 -04:00
|
|
|
Extendable::ExtensionError,
|
|
|
|
External::Processor::IncludeError => e
|
2018-09-11 10:29:48 -04:00
|
|
|
raise Config::ConfigError, e.message
|
2016-06-03 08:20:34 -04:00
|
|
|
end
|
|
|
|
|
2016-06-09 08:48:40 -04:00
|
|
|
def valid?
|
2016-06-16 08:16:33 -04:00
|
|
|
@global.valid?
|
2016-06-09 08:48:40 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def errors
|
2016-06-16 08:16:33 -04:00
|
|
|
@global.errors
|
2016-06-09 08:48:40 -04:00
|
|
|
end
|
|
|
|
|
2016-06-03 08:20:34 -04:00
|
|
|
def to_hash
|
|
|
|
@config
|
|
|
|
end
|
2016-11-18 08:30:27 -05: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 09:04:58 -04:00
|
|
|
|
2018-09-08 08:55:36 -04:00
|
|
|
private
|
|
|
|
|
2018-12-01 06:39:13 -05:00
|
|
|
def build_config(config, project:, sha:, user:)
|
2018-11-29 06:44:48 -05:00
|
|
|
initial_config = Gitlab::Config::Loader::Yaml.new(config).load!
|
2018-09-07 15:33:06 -04:00
|
|
|
|
2019-04-05 06:18:10 -04:00
|
|
|
process_external_files(initial_config, project: project, sha: sha, user: user)
|
2018-08-17 09:04:58 -04:00
|
|
|
end
|
2018-09-07 16:03:05 -04:00
|
|
|
|
2018-12-01 06:39:13 -05:00
|
|
|
def process_external_files(config, project:, sha:, user:)
|
|
|
|
Config::External::Processor.new(config,
|
|
|
|
project: project,
|
2019-04-05 06:18:10 -04:00
|
|
|
sha: sha || project&.repository&.root_ref_sha,
|
2019-01-14 05:55:51 -05:00
|
|
|
user: user,
|
|
|
|
expandset: Set.new).perform
|
2018-09-07 16:03:05 -04:00
|
|
|
end
|
2016-06-03 08:20:34 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|