Commit e19cb3b1 authored by Sean Arnold's avatar Sean Arnold

Merge branch 'lm-fix-failure-get-api-projects-id-lint' into 'master'

Add commit check to GET api/v4/projects

See merge request gitlab-org/gitlab!80189
parents b36e46b1 2a7328ca
...@@ -46,7 +46,10 @@ module API ...@@ -46,7 +46,10 @@ module API
get ':id/ci/lint', urgency: :low do get ':id/ci/lint', urgency: :low do
authorize! :download_code, user_project authorize! :download_code, user_project
content = user_project.repository.gitlab_ci_yml_for(user_project.commit.id, user_project.ci_config_path_or_default) if user_project.commit.present?
content = user_project.repository.gitlab_ci_yml_for(user_project.commit.id, user_project.ci_config_path_or_default)
end
result = Gitlab::Ci::Lint result = Gitlab::Ci::Lint
.new(project: user_project, current_user: current_user) .new(project: user_project, current_user: current_user)
.validate(content, dry_run: params[:dry_run]) .validate(content, dry_run: params[:dry_run])
......
...@@ -110,7 +110,7 @@ RSpec.describe API::Lint do ...@@ -110,7 +110,7 @@ RSpec.describe API::Lint do
context 'when authenticated' do context 'when authenticated' do
let_it_be(:api_user) { create(:user) } let_it_be(:api_user) { create(:user) }
context 'with valid .gitlab-ci.yaml content' do context 'with valid .gitlab-ci.yml content' do
let(:yaml_content) do let(:yaml_content) do
File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml')) File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
end end
...@@ -140,7 +140,7 @@ RSpec.describe API::Lint do ...@@ -140,7 +140,7 @@ RSpec.describe API::Lint do
end end
end end
context 'with valid .gitlab-ci.yaml with warnings' do context 'with valid .gitlab-ci.yml with warnings' do
let(:yaml_content) { { job: { script: 'ls', rules: [{ when: 'always' }] } }.to_yaml } let(:yaml_content) { { job: { script: 'ls', rules: [{ when: 'always' }] } }.to_yaml }
it 'passes validation but returns warnings' do it 'passes validation but returns warnings' do
...@@ -153,7 +153,7 @@ RSpec.describe API::Lint do ...@@ -153,7 +153,7 @@ RSpec.describe API::Lint do
end end
end end
context 'with valid .gitlab-ci.yaml using deprecated keywords' do context 'with valid .gitlab-ci.yml using deprecated keywords' do
let(:yaml_content) { { job: { script: 'ls', type: 'test' }, types: ['test'] }.to_yaml } let(:yaml_content) { { job: { script: 'ls', type: 'test' }, types: ['test'] }.to_yaml }
it 'passes validation but returns warnings' do it 'passes validation but returns warnings' do
...@@ -166,7 +166,7 @@ RSpec.describe API::Lint do ...@@ -166,7 +166,7 @@ RSpec.describe API::Lint do
end end
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' }
...@@ -384,6 +384,15 @@ RSpec.describe API::Lint do ...@@ -384,6 +384,15 @@ RSpec.describe API::Lint do
project.add_developer(api_user) project.add_developer(api_user)
end end
context 'with no commit' do
it 'returns error about providing content' do
ci_lint
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['errors']).to match_array(['Please provide content of .gitlab-ci.yml'])
end
end
context 'with valid .gitlab-ci.yml content' do context 'with valid .gitlab-ci.yml content' do
let(:yaml_content) do let(:yaml_content) do
{ include: { local: 'another-gitlab-ci.yml' }, test: { stage: 'test', script: 'echo 1' } }.to_yaml { include: { local: 'another-gitlab-ci.yml' }, test: { stage: 'test', script: 'echo 1' } }.to_yaml
......
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