BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
bbdc3571
Commit
bbdc3571
authored
Jul 20, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement method that updates a stage status
parent
e3895076
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
1 deletion
+66
-1
stage.rb
app/models/ci/stage.rb
+47
-0
stage_spec.rb
spec/models/ci/stage_spec.rb
+19
-1
No files found.
app/models/ci/stage.rb
View file @
bbdc3571
...
...
@@ -3,6 +3,7 @@ module Ci
extend
Ci
::
Model
include
Importable
include
HasStatus
include
Gitlab
::
OptimisticLocking
enumerate_status!
...
...
@@ -15,5 +16,51 @@ module Ci
validates
:project
,
presence:
true
,
unless: :importing?
validates
:pipeline
,
presence:
true
,
unless: :importing?
validates
:name
,
presence:
true
,
unless: :importing?
state_machine
:status
,
initial: :created
do
event
:enqueue
do
transition
created: :pending
transition
[
:success
,
:failed
,
:canceled
,
:skipped
]
=>
:running
end
event
:run
do
transition
any
-
[
:running
]
=>
:running
end
event
:skip
do
transition
any
-
[
:skipped
]
=>
:skipped
end
event
:drop
do
transition
any
-
[
:failed
]
=>
:failed
end
event
:succeed
do
transition
any
-
[
:success
]
=>
:success
end
event
:cancel
do
transition
any
-
[
:canceled
]
=>
:canceled
end
event
:block
do
transition
any
-
[
:manual
]
=>
:manual
end
end
def
update!
retry_optimistic_lock
(
self
)
do
case
commit_statuses
.
latest
.
status
when
'pending'
then
enqueue
when
'running'
then
run
when
'success'
then
succeed
when
'failed'
then
drop
when
'canceled'
then
cancel
when
'manual'
then
block
when
'skipped'
then
skip
else
skip
end
end
end
end
end
spec/models/ci/stage_spec.rb
View file @
bbdc3571
require
'spec_helper'
describe
Ci
::
Stage
,
:models
do
describe
'associations'
do
let
(
:stage
)
{
create
(
:ci_stage_entity
)
}
describe
'associations'
do
before
do
create
(
:ci_build
,
stage_id:
stage
.
id
)
create
(
:commit_status
,
stage_id:
stage
.
id
)
...
...
@@ -39,4 +39,22 @@ describe Ci::Stage, :models do
end
end
end
describe
'update!'
do
context
'when stage objects needs to be updated'
do
before
do
create
(
:ci_build
,
:success
,
stage_id:
stage
.
id
)
create
(
:ci_build
,
:running
,
stage_id:
stage
.
id
)
end
it
'updates stage status correctly'
do
expect
{
stage
.
update!
}
.
to
change
{
stage
.
reload
.
status
}
.
to
'running'
end
end
context
'when stage object is locked'
do
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