summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/lint.rb34
-rw-r--r--lib/ci/gitlab_ci_yaml_processor.rb9
2 files changed, 25 insertions, 18 deletions
diff --git a/lib/api/lint.rb b/lib/api/lint.rb
index 68eabb571d6..2d27bc65462 100644
--- a/lib/api/lint.rb
+++ b/lib/api/lint.rb
@@ -7,31 +7,29 @@ module API
desc 'Validation of .gitlab-ci.yml content'
post do
- status 200
-
- begin
- response = {
- status: '',
- errors: [],
- jobs: []
- }
-
- config_processor = Ci::GitlabCiYamlProcessor.new(params[:content])
-
- config_processor.builds.each do |build|
- response[:jobs].push("#{build[:name]}")
- response[:status] = 'valid'
- end
-
- response
+ response = {
+ status: '',
+ errors: [],
+ jobs: []
+ }
- rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
+ if Ci::GitlabCiYamlProcessor.validate(@content) != "valid"
status 200
response[:errors].push(e.message)
response[:status] = 'invalid'
response
end
+
+ config_processor = Ci::GitlabCiYamlProcessor.new(params[:content])
+
+ config_processor.builds.each do |build|
+ response[:jobs].push("#{build[:name]}")
+ response[:status] = 'valid'
+ end
+
+ status 200
+ response
end
end
end
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb
index 47efd5bd9f2..9799f494df6 100644
--- a/lib/ci/gitlab_ci_yaml_processor.rb
+++ b/lib/ci/gitlab_ci_yaml_processor.rb
@@ -78,6 +78,15 @@ module Ci
}
end
+ def self.validate(content)
+ begin
+ Ci::GitlabCiYamlProcessor.new(content)
+ "valid"
+ rescue ValidationError, Psych::SyntaxError => e
+ e.message
+ end
+ end
+
private
def initial_parsing