Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
214a372a
Commit
214a372a
authored
Nov 05, 2020
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds warnings to API response for linting
parent
3f739faf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
2 deletions
+33
-2
lib/api/lint.rb
lib/api/lint.rb
+3
-2
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+30
-0
No files found.
lib/api/lint.rb
View file @
214a372a
...
...
@@ -13,13 +13,14 @@ module API
post
'/lint'
do
result
=
Gitlab
::
Ci
::
YamlProcessor
.
new
(
params
[
:content
],
user:
current_user
).
execute
error
=
result
.
errors
.
first
warning
=
result
.
warnings
.
first
status
200
response
=
if
error
.
blank?
{
status:
'valid'
,
errors:
[]
}
{
status:
'valid'
,
errors:
[]
,
warnings:
[
warning
]
}
else
{
status:
'invalid'
,
errors:
[
error
]
}
{
status:
'invalid'
,
errors:
[
error
]
,
warnings:
[]
}
end
response
.
tap
do
|
response
|
...
...
spec/requests/api/lint_spec.rb
View file @
214a372a
...
...
@@ -26,6 +26,19 @@ RSpec.describe API::Lint do
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 invalid syntax'
do
let
(
:yaml_content
)
{
'invalid content'
}
...
...
@@ -82,6 +95,17 @@ RSpec.describe API::Lint do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
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
it
'passes validation'
do
ci_lint
...
...
@@ -250,6 +274,12 @@ RSpec.describe API::Lint do
it_behaves_like
'valid config'
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
context
'with invalid .gitlab-ci.yml content'
do
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment