debian-mirror-gitlab/lib/gitlab/ci/config.rb

89 lines
1.8 KiB
Ruby
Raw Normal View History

module Gitlab
module Ci
2018-12-05 23:21:45 +05:30
#
# Base GitLab CI Configuration facade
#
class Config
2018-11-20 20:47:30 +05:30
ConfigError = Class.new(StandardError)
2018-05-09 12:01:36 +05:30
def initialize(config, opts = {})
2018-11-20 20:47:30 +05:30
@config = Config::Extendable
.new(build_config(config, opts))
.to_hash
2017-08-17 22:00:37 +05:30
@global = Entry::Global.new(@config)
2016-09-29 09:46:39 +05:30
@global.compose!
2018-11-20 20:47:30 +05:30
rescue Loader::FormatError, Extendable::ExtensionError => e
raise Config::ConfigError, e.message
2018-12-05 23:21:45 +05:30
rescue ::Gitlab::Ci::External::Processor::FileError => e
raise ::Gitlab::Ci::YamlProcessor::ValidationError, e.message
end
2016-08-24 12:49:21 +05:30
def valid?
@global.valid?
end
def errors
@global.errors
end
def to_hash
@config
end
2017-08-17 22:00:37 +05:30
##
# 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-11-20 20:47:30 +05:30
2018-12-05 23:21:45 +05:30
private
2018-11-20 20:47:30 +05:30
def build_config(config, opts = {})
2018-12-05 23:21:45 +05:30
initial_config = Loader.new(config).load!
project = opts.fetch(:project, nil)
if project
process_external_files(initial_config, project, opts)
else
initial_config
end
end
def process_external_files(config, project, opts)
sha = opts.fetch(:sha) { project.repository.root_ref_sha }
::Gitlab::Ci::External::Processor.new(config, project, sha).perform
2018-11-20 20:47:30 +05:30
end
end
end
end