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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
257c2acd
Commit
257c2acd
authored
Aug 24, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add params requires to lint
parent
0e4c0e78
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
44 deletions
+35
-44
lib/ci/api/api.rb
lib/ci/api/api.rb
+1
-1
lib/ci/api/lint.rb
lib/ci/api/lint.rb
+20
-20
spec/requests/ci/api/lint_spec.rb
spec/requests/ci/api/lint_spec.rb
+14
-23
No files found.
lib/ci/api/api.rb
View file @
257c2acd
...
@@ -22,9 +22,9 @@ module Ci
...
@@ -22,9 +22,9 @@ module Ci
helpers
Gitlab
::
CurrentSettings
helpers
Gitlab
::
CurrentSettings
mount
::
Ci
::
API
::
Builds
mount
::
Ci
::
API
::
Builds
mount
::
Ci
::
API
::
Lint
mount
::
Ci
::
API
::
Runners
mount
::
Ci
::
API
::
Runners
mount
::
Ci
::
API
::
Triggers
mount
::
Ci
::
API
::
Triggers
mount
::
Ci
::
API
::
Lint
end
end
end
end
end
end
lib/ci/api/lint.rb
View file @
257c2acd
module
Ci
module
Ci
module
API
module
API
class
Lint
<
Grape
::
API
class
Lint
<
Grape
::
API
before
{
authenticate!
}
resource
:lint
do
resources
:lint
do
post
do
post
do
begin
status
200
response
=
{}
params
do
@content
=
params
[
:content
]
requires
:content
,
type:
String
,
desc:
'content of .gitlab-ci.yml'
end
if
@content
begin
@config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
@content
)
response
=
{
@stages
=
@config_processor
.
stages
status:
''
,
@builds
=
@config_processor
.
builds
errors:
[],
jobs:
[]
}
response
=
{
config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
params
[
:content
])
content:
@content
,
status:
"syntax is correct"
}
@stages
.
each
do
|
stage
|
config_processor
.
builds
.
each
do
|
build
|
response
[
"
#{
stage
}
"
]
=
@builds
.
select
{
|
build
|
build
[
:stage
]
==
stage
}
response
[
:jobs
].
push
(
"
#{
build
[
:name
]
}
"
)
end
response
[
:status
]
=
'valid'
else
render_api_error!
(
"Please provide content of .gitlab-ci.yml"
,
400
)
end
end
response
response
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
error!
({
content:
@content
,
status:
"syntax is incorrect"
,
message:
e
.
message
})
status
200
response
[
:errors
].
push
(
e
.
message
)
response
[
:status
]
=
'invalid'
response
end
end
end
end
end
end
...
...
spec/requests/ci/api/lint_spec.rb
View file @
257c2acd
...
@@ -9,41 +9,32 @@ describe Ci::API::API do
...
@@ -9,41 +9,32 @@ describe Ci::API::API do
end
end
describe
'POST /ci/lint'
do
describe
'POST /ci/lint'
do
context
"with valid .gitlab-ci.yaml content"
do
context
'with valid .gitlab-ci.yaml content'
do
context
"authorized user"
do
context
'authorized user'
do
it
"validate content"
do
it
'validate content'
do
post
ci_api
(
'/lint'
),
{
private_token:
user
.
private_token
,
content:
yaml_content
}
expect
(
response
).
to
have_http_status
(
201
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'status'
]).
to
eq
(
'syntax is correct'
)
end
end
context
"unauthorized user"
do
it
"does not validate content"
do
post
ci_api
(
'/lint'
),
{
content:
yaml_content
}
post
ci_api
(
'/lint'
),
{
content:
yaml_content
}
expect
(
response
).
to
have_http_status
(
401
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'status'
]).
to
eq
(
'valid'
)
end
end
end
end
end
end
context
"with invalid .gitlab_ci.yml content"
do
context
'with invalid .gitlab_ci.yml content'
do
it
"validate content"
do
it
'validate content'
do
post
ci_api
(
'/lint'
),
{
private_token:
user
.
private_token
,
content:
'invalid content'
}
post
ci_api
(
'/lint'
),
{
content:
'invalid content'
}
expect
(
response
).
to
have_http_status
(
5
00
)
expect
(
response
).
to
have_http_status
(
2
00
)
expect
(
json_response
[
'status'
]).
to
eq
(
'
syntax is incorrect
'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'
invalid
'
)
end
end
end
end
context
"no content"
do
context
'no content parameters'
do
it
"shows error message"
do
it
'shows error message'
do
post
ci_api
(
'/lint'
)
,
{
private_token:
user
.
private_token
}
post
ci_api
(
'/lint'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Please provide content of .gitlab-ci.yml'
)
end
end
end
end
end
end
...
...
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