gitlab-org--gitlab-foss/lib/api/lint.rb

30 lines
905 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-08-24 05:42:48 -04:00
module API
class Lint < Grape::API::Instance
2016-08-30 09:38:36 -04:00
namespace :ci do
2016-09-07 06:19:36 -04:00
desc 'Validation of .gitlab-ci.yml content'
params do
requires :content, type: String, desc: 'Content of .gitlab-ci.yml'
optional :include_merged_yaml, type: Boolean, desc: 'Whether or not to include merged CI config yaml in the response'
2016-09-07 06:19:36 -04:00
end
2016-08-30 07:03:29 -04:00
post '/lint' do
result = Gitlab::Ci::YamlProcessor.new(params[:content], user: current_user).execute
error = result.errors.first
2016-08-30 07:03:29 -04:00
status 200
2016-08-29 09:07:19 -04:00
response = if error.blank?
{ status: 'valid', errors: [] }
else
{ status: 'invalid', errors: [error] }
end
response.tap do |response|
response[:merged_yaml] = result.merged_yaml if params[:include_merged_yaml]
2016-08-30 07:03:29 -04:00
end
end
2016-08-24 05:42:48 -04:00
end
end
end