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
Boxiang Sun
gitlab-ce
Commits
1a7a900d
Commit
1a7a900d
authored
Aug 30, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code
parent
2c8b830f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
29 deletions
+25
-29
lib/api/lint.rb
lib/api/lint.rb
+10
-14
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+6
-9
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+6
-3
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+3
-3
No files found.
lib/api/lint.rb
View file @
1a7a900d
...
...
@@ -5,22 +5,18 @@ module API
requires
:content
,
type:
String
,
desc:
'Content of .gitlab-ci.yml'
end
post
'ci/lint'
do
error
=
Ci
::
GitlabCiYamlProcessor
.
validation_message
(
params
[
:content
])
response
=
{
status:
''
,
error:
''
}
namespace
'ci'
do
post
'/lint'
do
errors
=
Ci
::
GitlabCiYamlProcessor
.
validation_message
(
params
[
:content
])
if
error
.
blank?
response
[
:status
]
=
'valid'
else
response
[
:error
]
=
error
response
[
:status
]
=
'invalid'
end
status
200
status
200
response
if
errors
.
blank?
{
status:
'valid'
,
errors:
[]
}
else
{
status:
'invalid'
,
errors:
[
errors
]
}
end
end
end
end
end
lib/ci/gitlab_ci_yaml_processor.rb
View file @
1a7a900d
...
...
@@ -79,15 +79,12 @@ module Ci
end
def
self
.
validation_message
(
content
)
if
content
.
blank?
'Please provide content of .gitlab-ci.yml'
else
begin
Ci
::
GitlabCiYamlProcessor
.
new
(
content
)
nil
rescue
ValidationError
,
Psych
::
SyntaxError
=>
e
e
.
message
end
return
'Please provide content of .gitlab-ci.yml'
if
content
.
blank?
begin
Ci
::
GitlabCiYamlProcessor
.
new
(
content
)
nil
rescue
ValidationError
,
Psych
::
SyntaxError
=>
e
e
.
message
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
1a7a900d
...
...
@@ -1256,7 +1256,8 @@ EOT
it
"returns an error about invalid configutaion"
do
content
=
YAML
.
dump
(
"invalid: yaml: test"
)
expect
(
GitlabCiYamlProcessor
.
validation_message
(
content
)).
to
eq
"Invalid configuration format"
expect
(
GitlabCiYamlProcessor
.
validation_message
(
content
))
.
to
eq
"Invalid configuration format"
end
end
...
...
@@ -1264,13 +1265,15 @@ EOT
it
"returns an error about invalid tags"
do
content
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
tags:
"mysql"
}
})
expect
(
GitlabCiYamlProcessor
.
validation_message
(
content
)).
to
eq
"jobs:rspec tags should be an array of strings"
expect
(
GitlabCiYamlProcessor
.
validation_message
(
content
))
.
to
eq
"jobs:rspec tags should be an array of strings"
end
end
context
"when YMAL content is empty"
do
it
"returns an error about missing content"
do
expect
(
GitlabCiYamlProcessor
.
validation_message
(
''
)).
to
eq
"Please provide content of .gitlab-ci.yml"
expect
(
GitlabCiYamlProcessor
.
validation_message
(
''
))
.
to
eq
"Please provide content of .gitlab-ci.yml"
end
end
...
...
spec/requests/api/lint_spec.rb
View file @
1a7a900d
...
...
@@ -15,7 +15,7 @@ describe API::Lint, api: true do
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Hash
expect
(
json_response
[
'status'
]).
to
eq
(
'valid'
)
expect
(
json_response
[
'error
'
]).
to
eq
(
''
)
expect
(
json_response
[
'error
s'
]).
to
eq
([]
)
end
end
...
...
@@ -25,7 +25,7 @@ describe API::Lint, api: true do
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'error
'
]).
to
eq
(
'Invalid configuration format'
)
expect
(
json_response
[
'error
s'
]).
to
eq
([
'Invalid configuration format'
]
)
end
it
"responds with errors about invalid configuration"
do
...
...
@@ -33,7 +33,7 @@ describe API::Lint, api: true do
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'error
'
]).
to
eq
(
'jobs config should contain at least one visible job'
)
expect
(
json_response
[
'error
s'
]).
to
eq
([
'jobs config should contain at least one visible job'
]
)
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