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
114c26cc
Commit
114c26cc
authored
Jun 04, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise error if pipeline / stage hits unknown status
parent
93241149
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
61 additions
and
1 deletion
+61
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-1
app/models/ci/stage.rb
app/models/ci/stage.rb
+4
-0
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+2
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+37
-0
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+13
-0
No files found.
app/models/ci/pipeline.rb
View file @
114c26cc
...
...
@@ -517,7 +517,8 @@ module Ci
def
update_status
retry_optimistic_lock
(
self
)
do
case
latest_builds_status
case
latest_builds_status
.
to_s
when
'created'
then
nil
when
'pending'
then
enqueue
when
'running'
then
run
when
'success'
then
succeed
...
...
@@ -525,6 +526,9 @@ module Ci
when
'canceled'
then
cancel
when
'skipped'
then
skip
when
'manual'
then
block
else
raise
HasStatus
::
UnknownStatusError
,
"Unknown status `
#{
latest_builds_status
}
`"
end
end
end
...
...
app/models/ci/stage.rb
View file @
114c26cc
...
...
@@ -68,6 +68,7 @@ module Ci
def
update_status
retry_optimistic_lock
(
self
)
do
case
statuses
.
latest
.
status
when
'created'
then
nil
when
'pending'
then
enqueue
when
'running'
then
run
when
'success'
then
succeed
...
...
@@ -75,6 +76,9 @@ module Ci
when
'canceled'
then
cancel
when
'manual'
then
block
when
'skipped'
,
nil
then
skip
else
raise
HasStatus
::
UnknownStatusError
,
"Unknown status `
#{
statuses
.
latest
.
status
}
`"
end
end
end
...
...
app/models/concerns/has_status.rb
View file @
114c26cc
...
...
@@ -11,6 +11,8 @@ module HasStatus
STATUSES_ENUM
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
}.
freeze
UnknownStatusError
=
Class
.
new
(
StandardError
)
class_methods
do
def
status_sql
scope_relevant
=
respond_to?
(
:exclude_ignored
)
?
exclude_ignored
:
all
...
...
spec/models/ci/pipeline_spec.rb
View file @
114c26cc
...
...
@@ -1251,6 +1251,43 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'#update_status'
do
context
'when pipeline is empty'
do
it
'updates does not change pipeline status'
do
expect
(
pipeline
.
statuses
.
latest
.
status
).
to
be_nil
expect
{
pipeline
.
update_status
}
.
to
change
{
pipeline
.
reload
.
status
}.
to
'skipped'
end
end
context
'when updating status to pending'
do
before
do
allow
(
pipeline
)
.
to
receive_message_chain
(
:statuses
,
:latest
,
:status
)
.
and_return
(
:running
)
end
it
'updates pipeline status to running'
do
expect
{
pipeline
.
update_status
}
.
to
change
{
pipeline
.
reload
.
status
}.
to
'running'
end
end
context
'when statuses status was not recognized'
do
before
do
allow
(
pipeline
)
.
to
receive
(
:latest_builds_status
)
.
and_return
(
:unknown
)
end
it
'raises an exception'
do
expect
{
pipeline
.
update_status
}
.
to
raise_error
(
HasStatus
::
UnknownStatusError
)
end
end
end
describe
'#detailed_status'
do
subject
{
pipeline
.
detailed_status
(
user
)
}
...
...
spec/models/ci/stage_spec.rb
View file @
114c26cc
...
...
@@ -110,6 +110,19 @@ describe Ci::Stage, :models do
expect
(
stage
.
reload
).
to
be_failed
end
end
context
'when statuses status was not recognized'
do
before
do
allow
(
stage
)
.
to
receive_message_chain
(
:statuses
,
:latest
,
:status
)
.
and_return
(
:unknown
)
end
it
'raises an exception'
do
expect
{
stage
.
update_status
}
.
to
raise_error
(
HasStatus
::
UnknownStatusError
)
end
end
end
describe
'#detailed_status'
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