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
Jérome Perrin
gitlab-ce
Commits
10253707
Commit
10253707
authored
Apr 13, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CiStatus implementation and tests
parent
4d72ca39
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
app/models/commit_status.rb
app/models/commit_status.rb
+0
-2
app/models/concerns/ci_status.rb
app/models/concerns/ci_status.rb
+11
-9
spec/lib/ci/status_spec.rb
spec/lib/ci/status_spec.rb
+1
-1
No files found.
app/models/commit_status.rb
View file @
10253707
...
@@ -51,8 +51,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -51,8 +51,6 @@ class CommitStatus < ActiveRecord::Base
scope
:ordered
,
->
{
order
(
:ref
,
:stage_idx
,
:name
)
}
scope
:ordered
,
->
{
order
(
:ref
,
:stage_idx
,
:name
)
}
scope
:ignored
,
->
{
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
}
scope
:ignored
,
->
{
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
])
}
AVAILABLE_STATUSES
=
[
'pending'
,
'running'
,
'success'
,
'failed'
,
'canceled'
]
state_machine
:status
,
initial: :pending
do
state_machine
:status
,
initial: :pending
do
event
:run
do
event
:run
do
transition
pending: :running
transition
pending: :running
...
...
app/models/concerns/ci_status.rb
View file @
10253707
module
CiStatus
module
CiStatus
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
module
ClassMethods
AVAILABLE_STATUSES
=
%w(pending running success failed canceled skipped)
class_methods
do
def
status_sql
def
status_sql
builds
=
all
.
select
(
'count(
id
)'
).
to_sql
builds
=
all
.
select
(
'count(
*
)'
).
to_sql
success
=
all
.
success
.
select
(
'count(
id
)'
).
to_sql
success
=
all
.
success
.
select
(
'count(
*
)'
).
to_sql
ignored
=
all
.
failed
.
where
(
allow_failure:
true
).
select
(
'count(id
)'
).
to_sql
if
all
.
try
(
:ignored
)
ignored
=
all
.
ignored
.
select
(
'count(*
)'
).
to_sql
if
all
.
try
(
:ignored
)
ignored
||=
'0'
ignored
||=
'0'
pending
=
all
.
pending
.
select
(
'count(
id
)'
).
to_sql
pending
=
all
.
pending
.
select
(
'count(
*
)'
).
to_sql
running
=
all
.
running
.
select
(
'count(
id
)'
).
to_sql
running
=
all
.
running
.
select
(
'count(
*
)'
).
to_sql
canceled
=
all
.
canceled
.
select
(
'count(
id
)'
).
to_sql
canceled
=
all
.
canceled
.
select
(
'count(
*
)'
).
to_sql
deduce_status
=
"(CASE
deduce_status
=
"(CASE
WHEN (
#{
builds
}
)=0 THEN 'skipped'
WHEN (
#{
builds
}
)=0 THEN 'skipped'
...
@@ -24,7 +26,7 @@ module CiStatus
...
@@ -24,7 +26,7 @@ module CiStatus
end
end
def
status
def
status
pluck
(
self
.
status_sql
).
first
all
.
pluck
(
self
.
status_sql
).
first
end
end
def
duration
def
duration
...
@@ -34,7 +36,7 @@ module CiStatus
...
@@ -34,7 +36,7 @@ module CiStatus
end
end
included
do
included
do
validates
:status
,
inclusion:
{
in:
%w(pending running failed success canceled skipped)
}
validates
:status
,
inclusion:
{
in:
AVAILABLE_STATUSES
}
state_machine
:status
,
initial: :pending
do
state_machine
:status
,
initial: :pending
do
state
:pending
,
value:
'pending'
state
:pending
,
value:
'pending'
...
...
spec/lib/ci/status_spec.rb
View file @
10253707
...
@@ -8,7 +8,7 @@ describe CiStatus do
...
@@ -8,7 +8,7 @@ describe CiStatus do
describe
'.status'
do
describe
'.status'
do
before
do
before
do
allow
(
@object
).
to
receive
(
:all
).
and_return
(
statuses
)
allow
(
@object
).
to
receive
(
:all
).
and_return
(
CommitStatus
.
where
(
id:
statuses
)
)
end
end
subject
{
@object
.
status
}
subject
{
@object
.
status
}
...
...
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