summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-06-07 16:05:26 +0000
committerRémy Coutable <remy@rymai.me>2016-06-07 16:05:26 +0000
commitbe78a556d9be2a553cffc68937d3ce50c15e5b9c (patch)
tree2925bd389bd710426356d03a0cbfe3d47b35a3e9 /lib
parent5b83abcc01bd4a24268126dc52019b9f11152a7c (diff)
parent5ef104df59211b022ed42e38e1cdbe950ff54388 (diff)
downloadgitlab-ce-be78a556d9be2a553cffc68937d3ce50c15e5b9c.tar.gz
Merge branch 'refactor/ci-config-add-facade' into 'master'
Add new GitLab CI configuration facade class ## What does this MR do? This MR is a first iteration of major CI configuration refactoring. See #17139 and #15060 for more details. ## What are the relevant issue numbers? Closes #17139 See merge request !4462
Diffstat (limited to 'lib')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb10
-rw-r--r--lib/gitlab/ci/config.rb16
-rw-r--r--lib/gitlab/ci/config/loader.rb25
3 files changed, 44 insertions, 7 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 026a5ac97ca..130f5b0892e 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -12,18 +12,14 @@ module Ci
attr_reader :before_script, :after_script, :image, :services, :path, :cache
def initialize(config, path = nil)
- @config = YAML.safe_load(config, [Symbol], [], true)
+ @config = Gitlab::Ci::Config.new(config).to_hash
@path = path
- unless @config.is_a? Hash
- raise ValidationError, "YAML should be a hash"
- end
-
- @config = @config.deep_symbolize_keys
-
initial_parsing
validate!
+ rescue Gitlab::Ci::Config::Loader::FormatError => e
+ raise ValidationError, e.message
end
def builds_for_stage_and_ref(stage, ref, tag = false, trigger_request = nil)
diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb
new file mode 100644
index 00000000000..ffe633d4b63
--- /dev/null
+++ b/lib/gitlab/ci/config.rb
@@ -0,0 +1,16 @@
+module Gitlab
+ module Ci
+ class Config
+ class LoaderError < StandardError; end
+
+ def initialize(config)
+ loader = Loader.new(config)
+ @config = loader.load!
+ end
+
+ def to_hash
+ @config
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/loader.rb b/lib/gitlab/ci/config/loader.rb
new file mode 100644
index 00000000000..dbf6eb0edbe
--- /dev/null
+++ b/lib/gitlab/ci/config/loader.rb
@@ -0,0 +1,25 @@
+module Gitlab
+ module Ci
+ class Config
+ class Loader
+ class FormatError < StandardError; end
+
+ def initialize(config)
+ @config = YAML.safe_load(config, [Symbol], [], true)
+ end
+
+ def valid?
+ @config.is_a?(Hash)
+ end
+
+ def load!
+ unless valid?
+ raise FormatError, 'Invalid configuration format'
+ end
+
+ @config.deep_symbolize_keys
+ end
+ end
+ end
+ end
+end