From 1a7a900d8e4a4a3a65b33054168fdd86f252b757 Mon Sep 17 00:00:00 2001 From: Katarzyna Kobierska Date: Tue, 30 Aug 2016 13:03:29 +0200 Subject: Improve code --- lib/api/lint.rb | 24 ++++++++++-------------- lib/ci/gitlab_ci_yaml_processor.rb | 15 ++++++--------- 2 files changed, 16 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/api/lint.rb b/lib/api/lint.rb index b1c6f52bccb..98010cf3b68 100644 --- a/lib/api/lint.rb +++ b/lib/api/lint.rb @@ -5,22 +5,18 @@ module API requires :content, type: String, desc: 'Content of .gitlab-ci.yml' end - post 'ci/lint' do - error = Ci::GitlabCiYamlProcessor.validation_message(params[:content]) - response = { - status: '', - error: '' - } + namespace 'ci' do + post '/lint' do + errors = Ci::GitlabCiYamlProcessor.validation_message(params[:content]) - if error.blank? - response[:status] = 'valid' - else - response[:error] = error - response[:status] = 'invalid' - end + status 200 - status 200 - response + if errors.blank? + { status: 'valid', errors: [] } + else + { status: 'invalid', errors: [errors] } + end + end end end end diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index c547193ce4c..bdae3205511 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -79,15 +79,12 @@ module Ci end def self.validation_message(content) - if content.blank? - 'Please provide content of .gitlab-ci.yml' - else - begin - Ci::GitlabCiYamlProcessor.new(content) - nil - rescue ValidationError, Psych::SyntaxError => e - e.message - end + return 'Please provide content of .gitlab-ci.yml' if content.blank? + begin + Ci::GitlabCiYamlProcessor.new(content) + nil + rescue ValidationError, Psych::SyntaxError => e + e.message end end -- cgit v1.2.3