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

87 lines
1.9 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
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)
2019-09-30 21:07:59 +05:30
RESCUE_ERRORS = [
Gitlab::Config::Loader::FormatError,
Extendable::ExtensionError,
External::Processor::IncludeError
].freeze
attr_reader :root
2019-02-15 15:39:39 +05:30
def initialize(config, project: nil, sha: nil, user: nil)
2018-11-20 20:47:30 +05:30
@config = Config::Extendable
2019-02-15 15:39:39 +05:30
.new(build_config(config, project: project, sha: sha, user: user))
2018-11-20 20:47:30 +05:30
.to_hash
2019-09-30 21:07:59 +05:30
@root = Entry::Root.new(@config)
@root.compose!
2019-07-07 11:18:12 +05:30
rescue Gitlab::Config::Loader::Yaml::DataTooLargeError => e
Gitlab::Sentry.track_exception(e, extra: { user: user.inspect, project: project.inspect })
raise Config::ConfigError, e.message
2019-09-30 21:07:59 +05:30
rescue *rescue_errors => e
2018-11-20 20:47:30 +05:30
raise Config::ConfigError, e.message
end
2016-08-24 12:49:21 +05:30
def valid?
2019-09-30 21:07:59 +05:30
@root.valid?
2016-08-24 12:49:21 +05:30
end
def errors
2019-09-30 21:07:59 +05:30
@root.errors
2016-08-24 12:49:21 +05:30
end
def to_hash
@config
end
2017-08-17 22:00:37 +05:30
##
# Temporary method that should be removed after refactoring
#
def variables
2019-09-30 21:07:59 +05:30
root.variables_value
2017-08-17 22:00:37 +05:30
end
def stages
2019-09-30 21:07:59 +05:30
root.stages_value
2017-08-17 22:00:37 +05:30
end
def jobs
2019-09-30 21:07:59 +05:30
root.jobs_value
2017-08-17 22:00:37 +05:30
end
2018-11-20 20:47:30 +05:30
2018-12-05 23:21:45 +05:30
private
2019-02-15 15:39:39 +05:30
def build_config(config, project:, sha:, user:)
initial_config = Gitlab::Config::Loader::Yaml.new(config).load!
2018-12-05 23:21:45 +05:30
2019-07-31 22:56:46 +05:30
process_external_files(initial_config, project: project, sha: sha, user: user)
2018-12-05 23:21:45 +05:30
end
2019-02-15 15:39:39 +05:30
def process_external_files(config, project:, sha:, user:)
Config::External::Processor.new(config,
project: project,
2019-07-31 22:56:46 +05:30
sha: sha || project&.repository&.root_ref_sha,
2019-07-07 11:18:12 +05:30
user: user,
expandset: Set.new).perform
2018-11-20 20:47:30 +05:30
end
2019-09-30 21:07:59 +05:30
# Overriden in EE
def rescue_errors
RESCUE_ERRORS
end
end
end
end
2019-12-04 20:38:33 +05:30
Gitlab::Ci::Config.prepend_if_ee('EE::Gitlab::Ci::ConfigEE')