diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/api/api.rb | 2 | ||||
-rw-r--r-- | lib/ci/api/lint.rb | 40 |
2 files changed, 21 insertions, 21 deletions
diff --git a/lib/ci/api/api.rb b/lib/ci/api/api.rb index 741a81ca8f0..00572e6efdb 100644 --- a/lib/ci/api/api.rb +++ b/lib/ci/api/api.rb @@ -22,9 +22,9 @@ module Ci helpers Gitlab::CurrentSettings mount ::Ci::API::Builds + mount ::Ci::API::Lint mount ::Ci::API::Runners mount ::Ci::API::Triggers - mount ::Ci::API::Lint end end end diff --git a/lib/ci/api/lint.rb b/lib/ci/api/lint.rb index fab4f8d5925..6ea91ac34dd 100644 --- a/lib/ci/api/lint.rb +++ b/lib/ci/api/lint.rb @@ -1,35 +1,35 @@ module Ci module API class Lint < Grape::API - before { authenticate! } - - resources :lint do + resource :lint do post do - begin - response = {} - @content = params[:content] + status 200 + params do + requires :content, type: String, desc: 'content of .gitlab-ci.yml' + end - if @content - @config_processor = Ci::GitlabCiYamlProcessor.new(@content) - @stages = @config_processor.stages - @builds = @config_processor.builds + begin + response = { + status: '', + errors: [], + jobs: [] + } - response = { - content: @content, - status: "syntax is correct" - } + config_processor = Ci::GitlabCiYamlProcessor.new(params[:content]) - @stages.each do |stage| - response["#{stage}"] = @builds.select { |build| build[:stage] == stage } - end - else - render_api_error!("Please provide content of .gitlab-ci.yml", 400) + config_processor.builds.each do |build| + response[:jobs].push("#{build[:name]}") + response[:status] = 'valid' end response rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e - error!({ content: @content, status: "syntax is incorrect", message: e.message }) + status 200 + response[:errors].push(e.message) + response[:status] = 'invalid' + + response end end end |