diff options
-rw-r--r-- | config/routes.rb | 3 | ||||
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/lint.rb | 38 | ||||
-rw-r--r-- | lib/ci/api/api.rb | 1 | ||||
-rw-r--r-- | lib/ci/api/lint.rb | 38 | ||||
-rw-r--r-- | spec/requests/api/lint_spec.rb (renamed from spec/requests/ci/api/lint_spec.rb) | 10 |
6 files changed, 47 insertions, 44 deletions
diff --git a/config/routes.rb b/config/routes.rb index 262a174437a..0b22923039e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/api/api.rb b/lib/api/api.rb index e14464c1b0d..a08fb056049 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -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 diff --git a/lib/api/lint.rb b/lib/api/lint.rb new file mode 100644 index 00000000000..68eabb571d6 --- /dev/null +++ b/lib/api/lint.rb @@ -0,0 +1,38 @@ +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 diff --git a/lib/ci/api/api.rb b/lib/ci/api/api.rb index 00572e6efdb..a6b9beecded 100644 --- a/lib/ci/api/api.rb +++ b/lib/ci/api/api.rb @@ -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 diff --git a/lib/ci/api/lint.rb b/lib/ci/api/lint.rb deleted file mode 100644 index 6ea91ac34dd..00000000000 --- a/lib/ci/api/lint.rb +++ /dev/null @@ -1,38 +0,0 @@ -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 diff --git a/spec/requests/ci/api/lint_spec.rb b/spec/requests/api/lint_spec.rb index cc3d77f3b38..9de9c90a4aa 100644 --- a/spec/requests/ci/api/lint_spec.rb +++ b/spec/requests/api/lint_spec.rb @@ -1,6 +1,6 @@ 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 |