summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-06 11:05:15 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-06-06 11:05:15 +0200
commit251dd571dfc3e6261ed075ecf725dd98ee176b69 (patch)
tree0da934217af029af78e1e90d9a63045fd11e2290 /lib
parent8048dcc8e693d713a94a7b9361672692f4e5932f (diff)
downloadgitlab-ce-251dd571dfc3e6261ed075ecf725dd98ee176b69.tar.gz
Extract CI config validation helpers to mixin
Diffstat (limited to 'lib')
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb18
-rw-r--r--lib/gitlab/ci/config/validation_helpers.rb26
2 files changed, 28 insertions, 16 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 46a923161c8..e470ec56b79 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -2,6 +2,8 @@ module Ci
class GitlabCiYamlProcessor
class ValidationError < StandardError; end
+ include Gitlab::Ci::Config::ValidationHelpers
+
DEFAULT_STAGES = %w(build test deploy)
DEFAULT_STAGE = 'test'
ALLOWED_YAML_KEYS = [:before_script, :after_script, :image, :services, :types, :stages, :variables, :cache]
@@ -276,22 +278,6 @@ module Ci
end
end
- def validate_array_of_strings(values)
- values.is_a?(Array) && values.all? { |value| validate_string(value) }
- end
-
- def validate_variables(variables)
- variables.is_a?(Hash) && variables.all? { |key, value| validate_string(key) && validate_string(value) }
- end
-
- def validate_string(value)
- value.is_a?(String) || value.is_a?(Symbol)
- end
-
- def validate_boolean(value)
- value.in?([true, false])
- end
-
def process?(only_params, except_params, ref, tag, trigger_request)
if only_params.present?
return false unless matching?(only_params, ref, tag, trigger_request)
diff --git a/lib/gitlab/ci/config/validation_helpers.rb b/lib/gitlab/ci/config/validation_helpers.rb
new file mode 100644
index 00000000000..9e4e9a83323
--- /dev/null
+++ b/lib/gitlab/ci/config/validation_helpers.rb
@@ -0,0 +1,26 @@
+module Gitlab
+ module Ci
+ class Config
+ module ValidationHelpers
+ private
+
+ def validate_array_of_strings(values)
+ values.is_a?(Array) && values.all? { |value| validate_string(value) }
+ end
+
+ def validate_variables(variables)
+ variables.is_a?(Hash) &&
+ variables.all? { |key, value| validate_string(key) && validate_string(value) }
+ end
+
+ def validate_string(value)
+ value.is_a?(String) || value.is_a?(Symbol)
+ end
+
+ def validate_boolean(value)
+ value.in?([true, false])
+ end
+ end
+ end
+ end
+end