diff options
author | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-08-25 13:40:35 +0200 |
---|---|---|
committer | Katarzyna Kobierska <kkobierska@gmail.com> | 2016-09-07 12:10:49 +0200 |
commit | 9e313c129418f847498e771abd6bea53884682b5 (patch) | |
tree | 0604e2383bde88722e7b565d54b188f90c426ebe /lib/api | |
parent | de2e8d4a559bd99479f46e527d8e78f67ad37de6 (diff) | |
download | gitlab-ce-9e313c129418f847498e771abd6bea53884682b5.tar.gz |
Add class method to encapsulate exception
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/lint.rb | 34 |
1 files changed, 16 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 |