Commit 214a372a authored by lauraMon's avatar lauraMon

Adds warnings to API response for linting

parent 3f739faf
...@@ -13,13 +13,14 @@ module API ...@@ -13,13 +13,14 @@ module API
post '/lint' do post '/lint' do
result = Gitlab::Ci::YamlProcessor.new(params[:content], user: current_user).execute result = Gitlab::Ci::YamlProcessor.new(params[:content], user: current_user).execute
error = result.errors.first error = result.errors.first
warning = result.warnings.first
status 200 status 200
response = if error.blank? response = if error.blank?
{ status: 'valid', errors: [] } { status: 'valid', errors: [], warnings: [warning] }
else else
{ status: 'invalid', errors: [error] } { status: 'invalid', errors: [error], warnings: [] }
end end
response.tap do |response| response.tap do |response|
......
...@@ -26,6 +26,19 @@ RSpec.describe API::Lint do ...@@ -26,6 +26,19 @@ RSpec.describe API::Lint do
end end
end end
context 'with valid .gitlab-ci.yaml but with warnings' do
let(:yaml_content) { { job: { script: 'ls', rules: [{ when: 'always' }] } }.to_yaml }
it 'passes validation but raises a warning' do
post api('/ci/lint'), params: { content: yaml_content }
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['warnings']).not_to be_empty
expect(json_response['status']).to eq('valid')
expect(json_response['errors']).to eq([])
end
end
context 'with an invalid .gitlab_ci.yml' do context 'with an invalid .gitlab_ci.yml' do
context 'with invalid syntax' do context 'with invalid syntax' do
let(:yaml_content) { 'invalid content' } let(:yaml_content) { 'invalid content' }
...@@ -82,6 +95,17 @@ RSpec.describe API::Lint do ...@@ -82,6 +95,17 @@ RSpec.describe API::Lint do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:dry_run) { nil } let(:dry_run) { nil }
RSpec.shared_examples 'valid config with warnings' do
it 'passes validation with warnings' do
ci_lint
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['valid']).to eq(true)
expect(json_response['errors']).to eq([])
expect(json_response['warnings']).not_to be_empty
end
end
RSpec.shared_examples 'valid config' do RSpec.shared_examples 'valid config' do
it 'passes validation' do it 'passes validation' do
ci_lint ci_lint
...@@ -250,6 +274,12 @@ RSpec.describe API::Lint do ...@@ -250,6 +274,12 @@ RSpec.describe API::Lint do
it_behaves_like 'valid config' it_behaves_like 'valid config'
end end
context 'With warnings' do
let(:yaml_content) { { job: { script: 'ls', rules: [{ when: 'always' }] } }.to_yaml }
it_behaves_like 'valid config with warnings'
end
end end
context 'with invalid .gitlab-ci.yml content' do context 'with invalid .gitlab-ci.yml content' do
......
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