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
234be12e
Commit
234be12e
authored
Apr 12, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimise CI status accessor
parent
8e84acbf
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
41 deletions
+22
-41
commit_status.rb
app/models/commit_status.rb
+0
-25
ci_status.rb
app/models/concerns/ci_status.rb
+22
-16
No files found.
app/models/commit_status.rb
View file @
234be12e
...
@@ -90,31 +90,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -90,31 +90,6 @@ class CommitStatus < ActiveRecord::Base
group
(
'stage'
).
order
(
order_by
).
pluck
(
:stage
,
order_by
).
map
(
&
:first
).
compact
group
(
'stage'
).
order
(
order_by
).
pluck
(
:stage
,
order_by
).
map
(
&
:first
).
compact
end
end
def
self
.
status_sql
builds
=
all
.
select
(
'count(id)'
).
to_sql
success
=
all
.
success
.
select
(
'count(id)'
).
to_sql
ignored
=
all
.
failed
.
where
(
allow_failure:
true
).
select
(
'count(id)'
).
to_sql
if
all
.
try
(
:ignored
)
ignored
||=
'0'
pending
=
all
.
pending
.
select
(
'count(id)'
).
to_sql
running
=
all
.
running
.
select
(
'count(id)'
).
to_sql
canceled
=
all
.
canceled
.
select
(
'count(id)'
).
to_sql
deduce_status
=
"(CASE
WHEN (
#{
builds
}
)=0 THEN 'skipped'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
ignored
}
) THEN 'success'
WHEN (
#{
builds
}
)=(
#{
pending
}
) THEN 'pending'
WHEN (
#{
builds
}
)=(
#{
canceled
}
) THEN 'canceled'
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN 'running'
ELSE 'failed'
END)"
deduce_status
end
def
self
.
status
pluck
(
self
.
status_sql
).
first
end
def
self
.
stages_status
def
self
.
stages_status
Hash
[
group
(
:stage
).
pluck
(
:stage
,
self
.
status_sql
)]
Hash
[
group
(
:stage
).
pluck
(
:stage
,
self
.
status_sql
)]
end
end
...
...
app/models/concerns/ci_status.rb
View file @
234be12e
...
@@ -2,23 +2,29 @@ module CiStatus
...
@@ -2,23 +2,29 @@ module CiStatus
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
module
ClassMethods
module
ClassMethods
def
status_sql
builds
=
all
.
select
(
'count(id)'
).
to_sql
success
=
all
.
success
.
select
(
'count(id)'
).
to_sql
ignored
=
all
.
failed
.
where
(
allow_failure:
true
).
select
(
'count(id)'
).
to_sql
if
all
.
try
(
:ignored
)
ignored
||=
'0'
pending
=
all
.
pending
.
select
(
'count(id)'
).
to_sql
running
=
all
.
running
.
select
(
'count(id)'
).
to_sql
canceled
=
all
.
canceled
.
select
(
'count(id)'
).
to_sql
deduce_status
=
"(CASE
WHEN (
#{
builds
}
)=0 THEN 'skipped'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
ignored
}
) THEN 'success'
WHEN (
#{
builds
}
)=(
#{
pending
}
) THEN 'pending'
WHEN (
#{
builds
}
)=(
#{
canceled
}
) THEN 'canceled'
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN 'running'
ELSE 'failed'
END)"
deduce_status
end
def
status
def
status
objs
=
all
.
to_a
pluck
(
self
.
status_sql
).
first
if
objs
.
none?
nil
elsif
objs
.
all?
{
|
status
|
status
.
success?
||
status
.
try
(
:ignored?
)
}
'success'
elsif
objs
.
all?
(
&
:pending?
)
'pending'
elsif
objs
.
any?
(
&
:running?
)
||
all
.
any?
(
&
:pending?
)
'running'
elsif
objs
.
all?
(
&
:canceled?
)
'canceled'
elsif
objs
.
all?
(
&
:skipped?
)
'skipped'
else
'failed'
end
end
end
def
duration
def
duration
...
...
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