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
bbba62fa
Commit
bbba62fa
authored
Aug 26, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix errors and grammar
parent
cfa18dab
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
25 deletions
+23
-25
lib/api/lint.rb
lib/api/lint.rb
+10
-13
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+4
-4
spec/requests/api/lint_spec.rb
spec/requests/api/lint_spec.rb
+9
-8
No files found.
lib/api/lint.rb
View file @
bbba62fa
...
@@ -9,24 +9,21 @@ module API
...
@@ -9,24 +9,21 @@ module API
post
do
post
do
response
=
{
response
=
{
status:
''
,
status:
''
,
error
s
:
[],
error:
[],
jobs:
[]
jobs:
[]
}
}
if
!
Ci
::
GitlabCiYamlProcessor
.
errors
(
@content
).
nil?
if
Ci
::
GitlabCiYamlProcessor
.
errors
(
params
[
:content
]).
nil?
status
200
response
[
:errors
].
push
(
Ci
::
GitlabCiYamlProcessor
.
errors
(
@content
))
response
[
:status
]
=
'invalid'
response
end
config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
params
[
:content
])
config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
params
[
:content
])
config_processor
.
builds
.
each
do
|
build
|
config_processor
.
builds
.
each
do
|
build
|
response
[
:jobs
].
push
(
"
#{
build
[
:name
]
}
"
)
response
[
:jobs
].
push
(
"
#{
build
[
:name
]
}
"
)
response
[
:status
]
=
'valid'
response
[
:status
]
=
'valid'
end
end
else
response
[
:error
].
push
(
Ci
::
GitlabCiYamlProcessor
.
errors
(
params
[
:content
]))
response
[
:status
]
=
'invalid'
end
status
200
status
200
response
response
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
bbba62fa
...
@@ -1251,19 +1251,19 @@ EOT
...
@@ -1251,19 +1251,19 @@ EOT
end
end
end
end
describe
"#errors
(content)
"
do
describe
"#errors"
do
describe
"Error handling"
do
describe
"Error handling"
do
it
"returns
error if parse YAML fail
ed"
do
it
"returns
an error if the YAML could not be pars
ed"
do
content
=
YAML
.
dump
(
"invalid: yaml: test"
)
content
=
YAML
.
dump
(
"invalid: yaml: test"
)
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
"Invalid configuration format"
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
"Invalid configuration format"
end
end
it
"returns
errors if
tags parameter is invalid"
do
it
"returns
an error if the
tags parameter is invalid"
do
content
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
tags:
"mysql"
}
})
content
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
tags:
"mysql"
}
})
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
"jobs:rspec tags should be an array of strings"
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
"jobs:rspec tags should be an array of strings"
end
end
it
"does not return
errors
"
do
it
"does not return
any errors when the YAML is valid
"
do
content
=
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
content
=
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
nil
expect
(
GitlabCiYamlProcessor
.
errors
(
content
)).
to
eq
nil
end
end
...
...
spec/requests/api/lint_spec.rb
View file @
bbba62fa
...
@@ -9,7 +9,7 @@ describe API::API do
...
@@ -9,7 +9,7 @@ describe API::API do
describe
'POST /lint'
do
describe
'POST /lint'
do
context
'with valid .gitlab-ci.yaml content'
do
context
'with valid .gitlab-ci.yaml content'
do
it
'validates content'
do
it
'validates
the
content'
do
post
api
(
'/lint'
),
{
content:
yaml_content
}
post
api
(
'/lint'
),
{
content:
yaml_content
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
...
@@ -18,29 +18,30 @@ describe API::API do
...
@@ -18,29 +18,30 @@ describe API::API do
end
end
end
end
context
'with invalid .gitlab_ci.yml'
do
context
'with
an
invalid .gitlab_ci.yml'
do
it
'validates
content and shows correct errors
'
do
it
'validates
the content and shows an error message
'
do
post
api
(
'/lint'
),
{
content:
'invalid content'
}
post
api
(
'/lint'
),
{
content:
'invalid content'
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'error
s
'
]).
to
eq
([
'Invalid configuration format'
])
expect
(
json_response
[
'error'
]).
to
eq
([
'Invalid configuration format'
])
end
end
it
"validates
content and shows
configuration error"
do
it
"validates
the content and shows a
configuration error"
do
post
api
(
'/lint'
),
{
content:
'{ image: "ruby:2.1", services: ["postgres"] }'
}
post
api
(
'/lint'
),
{
content:
'{ image: "ruby:2.1", services: ["postgres"] }'
}
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'status'
]).
to
eq
(
'invalid'
)
expect
(
json_response
[
'error
s
'
]).
to
eq
([
'jobs config should contain at least one visible job'
])
expect
(
json_response
[
'error'
]).
to
eq
([
'jobs config should contain at least one visible job'
])
end
end
end
end
context
'
no content parameters
'
do
context
'
without the content parameter
'
do
it
'shows error message'
do
it
'shows
an
error message'
do
post
api
(
'/lint'
)
post
api
(
'/lint'
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
response
).
to
have_http_status
(
400
)
expect
(
json_response
[
'error'
]).
to
eq
(
'content is missing'
)
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