Commit ca1f5ede authored by Katarzyna Kobierska's avatar Katarzyna Kobierska

Move lint to api from ci/api

parent 257c2acd
......@@ -81,6 +81,9 @@ Rails.application.routes.draw do
mount Sidekiq::Web, at: '/admin/sidekiq', as: :sidekiq
end
# Lint API
resources :lint, only: [:show, :create]
# Health check
get 'health_check(/:checks)' => 'health_check#index', as: :health_check
......
......@@ -45,6 +45,7 @@ module API
mount ::API::Keys
mount ::API::Labels
mount ::API::LicenseTemplates
mount ::API::Lint
mount ::API::Members
mount ::API::MergeRequests
mount ::API::Milestones
......
module API
class Lint < Grape::API
resource :lint do
params do
requires :content, type: String, desc: 'content of .gitlab-ci.yml'
end
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
rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
status 200
response[:errors].push(e.message)
response[:status] = 'invalid'
response
end
end
end
end
end
......@@ -22,7 +22,6 @@ module Ci
helpers Gitlab::CurrentSettings
mount ::Ci::API::Builds
mount ::Ci::API::Lint
mount ::Ci::API::Runners
mount ::Ci::API::Triggers
end
......
module Ci
module API
class Lint < Grape::API
resource :lint do
post do
status 200
params do
requires :content, type: String, desc: 'content of .gitlab-ci.yml'
end
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
rescue Ci::GitlabCiYamlProcessor::ValidationError, Psych::SyntaxError => e
status 200
response[:errors].push(e.message)
response[:status] = 'invalid'
response
end
end
end
end
end
end
require 'spec_helper'
describe Ci::API::API do
describe API::API do
include ApiHelpers
let(:user) { create(:user) }
......@@ -8,11 +8,11 @@ describe Ci::API::API do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end
describe 'POST /ci/lint' do
describe 'POST /lint' do
context 'with valid .gitlab-ci.yaml content' do
context 'authorized user' do
it 'validate content' do
post ci_api('/lint'), { content: yaml_content }
post api('/lint'), { content: yaml_content }
expect(response).to have_http_status(200)
expect(json_response).to be_an Hash
......@@ -23,7 +23,7 @@ describe Ci::API::API do
context 'with invalid .gitlab_ci.yml content' do
it 'validate content' do
post ci_api('/lint'), { content: 'invalid content' }
post api('/lint'), { content: 'invalid content' }
expect(response).to have_http_status(200)
expect(json_response['status']).to eq('invalid')
......@@ -32,7 +32,7 @@ describe Ci::API::API do
context 'no content parameters' do
it 'shows error message' do
post ci_api('/lint')
post api('/lint')
expect(response).to have_http_status(400)
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment