summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorValery Sizov <vsv2711@gmail.com>2015-06-16 15:12:36 +0300
committerValery Sizov <vsv2711@gmail.com>2015-06-17 11:35:39 +0300
commit40830fee8bcdfd465fb87fada28ef049a080acf2 (patch)
treede9b0e5351cbf0f05f04155e9ca97afa984dc456 /lib
parent58dcfe0e3d3bb7b12e3f7aa4aed49bd0cc97c912 (diff)
downloadgitlab-ci-40830fee8bcdfd465fb87fada28ef049a080acf2.tar.gz
better yaml validation
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab_ci_yaml_processor.rb46
1 files changed, 43 insertions, 3 deletions
diff --git a/lib/gitlab_ci_yaml_processor.rb b/lib/gitlab_ci_yaml_processor.rb
index 67903d5..51f412a 100644
--- a/lib/gitlab_ci_yaml_processor.rb
+++ b/lib/gitlab_ci_yaml_processor.rb
@@ -2,7 +2,7 @@ class GitlabCiYamlProcessor
attr_reader :before_script, :skip_refs, :errors
def initialize(config)
- @valid = true
+ @errors = []
@config = YAML.load(config).deep_symbolize_keys
@before_script = @config[:before_script] || []
@@ -14,11 +14,12 @@ class GitlabCiYamlProcessor
@deploy_jobs = @config.select{|key, value| value[:type] == "deploy"}
rescue Exception => e
- @valid = false
+ @errors << "Yaml file is invalid"
end
def valid?
- @valid
+ validate!
+ !@errors.any?
end
def deploy_builds_for_ref(ref, tag = false)
@@ -94,4 +95,43 @@ class GitlabCiYamlProcessor
script
end
end
+
+ def validate!
+ unless @config.is_a? Hash
+ @errors << "should be a hash"
+ return false
+ end
+
+ @jobs.each do |name, job|
+ if job[:tags] && !job[:tags].is_a?(Array)
+ @errors << "#{name} job: tags parameter should be an array"
+ end
+
+ if job[:only] && !job[:only].is_a?(Array)
+ @errors << "#{name} job: only parameter should be an array"
+ end
+
+ if job[:except] && !job[:except].is_a?(Array)
+ @errors << "#{name} job: except parameter should be an array"
+ end
+ end
+
+ @deploy_jobs.each do |name, job|
+ if job[:tags] && !job[:tags].is_a?(Array)
+ @errors << "#{name} deploy job: tags parameter should be an array"
+ end
+
+ if job[:only] && !job[:only].is_a?(Array)
+ @errors << "#{name} deploy job: only parameter should be an array"
+ end
+
+ if job[:except] && !job[:except].is_a?(Array)
+ @errors << "#{name} deploy job: except parameter should be an array"
+ end
+ end
+
+ true
+ rescue
+ @errors << "Undefined error"
+ end
end