From 9e313c129418f847498e771abd6bea53884682b5 Mon Sep 17 00:00:00 2001 From: Katarzyna Kobierska Date: Thu, 25 Aug 2016 13:40:35 +0200 Subject: Add class method to encapsulate exception --- lib/api/lint.rb | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'lib/api') 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 -- cgit v1.2.1