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
9e313c12
Commit
9e313c12
authored
Aug 25, 2016
by
Katarzyna Kobierska
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add class method to encapsulate exception
parent
de2e8d4a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
21 deletions
+47
-21
app/controllers/ci/lints_controller.rb
app/controllers/ci/lints_controller.rb
+3
-3
lib/api/lint.rb
lib/api/lint.rb
+16
-18
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+9
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+19
-0
No files found.
app/controllers/ci/lints_controller.rb
View file @
9e313c12
...
@@ -11,15 +11,15 @@ module Ci
...
@@ -11,15 +11,15 @@ module Ci
if
@content
.
blank?
if
@content
.
blank?
@status
=
false
@status
=
false
@error
=
"Please provide content of .gitlab-ci.yml"
@error
=
"Please provide content of .gitlab-ci.yml"
elsif
Ci
::
GitlabCiYamlProcessor
.
validate
(
@content
)
!=
"valid"
@status
=
false
@error
=
Ci
::
GitlabCiYamlProcessor
.
validate
(
@content
)
else
else
@config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
@content
)
@config_processor
=
Ci
::
GitlabCiYamlProcessor
.
new
(
@content
)
@stages
=
@config_processor
.
stages
@stages
=
@config_processor
.
stages
@builds
=
@config_processor
.
builds
@builds
=
@config_processor
.
builds
@status
=
true
@status
=
true
end
end
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
@error
=
e
.
message
@status
=
false
rescue
rescue
@error
=
'Undefined error'
@error
=
'Undefined error'
@status
=
false
@status
=
false
...
...
lib/api/lint.rb
View file @
9e313c12
...
@@ -7,15 +7,20 @@ module API
...
@@ -7,15 +7,20 @@ module API
desc
'Validation of .gitlab-ci.yml content'
desc
'Validation of .gitlab-ci.yml content'
post
do
post
do
status
200
begin
response
=
{
response
=
{
status:
''
,
status:
''
,
errors:
[],
errors:
[],
jobs:
[]
jobs:
[]
}
}
if
Ci
::
GitlabCiYamlProcessor
.
validate
(
@content
)
!=
"valid"
status
200
response
[
:errors
].
push
(
e
.
message
)
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
|
...
@@ -23,16 +28,9 @@ module API
...
@@ -23,16 +28,9 @@ module API
response
[
:status
]
=
'valid'
response
[
:status
]
=
'valid'
end
end
response
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
status
200
status
200
response
[
:errors
].
push
(
e
.
message
)
response
[
:status
]
=
'invalid'
response
response
end
end
end
end
end
end
end
end
end
lib/ci/gitlab_ci_yaml_processor.rb
View file @
9e313c12
...
@@ -78,6 +78,15 @@ module Ci
...
@@ -78,6 +78,15 @@ module Ci
}
}
end
end
def
self
.
validate
(
content
)
begin
Ci
::
GitlabCiYamlProcessor
.
new
(
content
)
"valid"
rescue
ValidationError
,
Psych
::
SyntaxError
=>
e
e
.
message
end
end
private
private
def
initial_parsing
def
initial_parsing
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
9e313c12
...
@@ -1250,5 +1250,24 @@ EOT
...
@@ -1250,5 +1250,24 @@ EOT
end
end
end
end
end
end
describe
"#validate(config)"
do
describe
"Error handling"
do
it
"returns error to parse YAML"
do
config
=
YAML
.
dump
(
"invalid: yaml: test"
)
expect
(
GitlabCiYamlProcessor
.
validate
(
config
)).
to
eq
"Invalid configuration format"
end
it
"returns errors if tags parameter is invalid"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
tags:
"mysql"
}
})
expect
(
GitlabCiYamlProcessor
.
validate
(
config
)).
to
eq
"jobs:rspec tags should be an array of strings"
end
it
"does not return errors"
do
config
=
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
expect
(
GitlabCiYamlProcessor
.
validate
(
config
)).
to
eq
"valid"
end
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