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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
35a464cc
Commit
35a464cc
authored
Aug 14, 2019
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove HasStatus.status
parent
b8003a78
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
37 deletions
+84
-37
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+3
-1
app/models/ci/stage.rb
app/models/ci/stage.rb
+7
-1
app/models/commit_status.rb
app/models/commit_status.rb
+6
-2
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+38
-4
lib/gitlab/ci/status/composite_status.rb
lib/gitlab/ci/status/composite_status.rb
+25
-25
spec/models/concerns/has_status_spec.rb
spec/models/concerns/has_status_spec.rb
+5
-4
No files found.
app/models/ci/pipeline.rb
View file @
35a464cc
...
...
@@ -904,7 +904,9 @@ module Ci
def
latest_builds_status
return
'failed'
unless
yaml_errors
.
blank?
statuses
.
latest
.
status
||
'skipped'
Gitlab
::
Ci
::
Status
::
GroupedStatuses
.
new
(
statuses
.
latest
)
.
one
[
:status
]
||
'skipped'
end
def
keep_around_commits
...
...
app/models/ci/stage.rb
View file @
35a464cc
...
...
@@ -78,7 +78,7 @@ module Ci
def
update_status
retry_optimistic_lock
(
self
)
do
case
statuses
.
latest
.
status
case
latest_stage_
status
when
'created'
then
nil
when
'preparing'
then
prepare
when
'pending'
then
enqueue
...
...
@@ -124,5 +124,11 @@ module Ci
def
manual_playable?
blocked?
||
skipped?
end
def
latest_stage_status
Gitlab
::
Ci
::
Status
::
GroupedStatuses
.
new
(
statuses
.
latest
)
.
one
[
:status
]
||
'skipped'
end
end
end
app/models/commit_status.rb
View file @
35a464cc
...
...
@@ -153,11 +153,15 @@ class CommitStatus < ApplicationRecord
end
def
self
.
status_for_prior_stages
(
index
)
before_stage
(
index
).
latest
.
status
||
'success'
Gitlab
::
Ci
::
Status
::
GroupedStatuses
.
new
(
before_stage
(
index
).
latest
)
.
one
[
:status
]
||
'success'
end
def
self
.
status_for_names
(
names
)
where
(
name:
names
).
latest
.
status
||
'success'
Gitlab
::
Ci
::
Status
::
GroupedStatuses
.
new
(
where
(
name:
names
).
latest
)
.
one
[
:status
]
||
'success'
end
def
locking_enabled?
...
...
app/models/concerns/has_status.rb
View file @
35a464cc
...
...
@@ -18,10 +18,44 @@ module HasStatus
UnknownStatusError
=
Class
.
new
(
StandardError
)
class_methods
do
def
status
Gitlab
::
Ci
::
Status
::
GroupedStatuses
.
new
(
all
)
.
one
[
:status
]
def
legacy_status_sql
scope_relevant
=
respond_to?
(
:exclude_ignored
)
?
exclude_ignored
:
all
scope_warnings
=
respond_to?
(
:failed_but_allowed
)
?
failed_but_allowed
:
none
builds
=
scope_relevant
.
select
(
'count(*)'
).
to_sql
created
=
scope_relevant
.
created
.
select
(
'count(*)'
).
to_sql
success
=
scope_relevant
.
success
.
select
(
'count(*)'
).
to_sql
manual
=
scope_relevant
.
manual
.
select
(
'count(*)'
).
to_sql
scheduled
=
scope_relevant
.
scheduled
.
select
(
'count(*)'
).
to_sql
preparing
=
scope_relevant
.
preparing
.
select
(
'count(*)'
).
to_sql
pending
=
scope_relevant
.
pending
.
select
(
'count(*)'
).
to_sql
running
=
scope_relevant
.
running
.
select
(
'count(*)'
).
to_sql
skipped
=
scope_relevant
.
skipped
.
select
(
'count(*)'
).
to_sql
canceled
=
scope_relevant
.
canceled
.
select
(
'count(*)'
).
to_sql
warnings
=
scope_warnings
.
select
(
'count(*) > 0'
).
to_sql
.
presence
||
'false'
Arel
.
sql
(
"(CASE
WHEN (
#{
builds
}
)=(
#{
skipped
}
) AND (
#{
warnings
}
) THEN 'success'
WHEN (
#{
builds
}
)=(
#{
skipped
}
) THEN 'skipped'
WHEN (
#{
builds
}
)=(
#{
success
}
) THEN 'success'
WHEN (
#{
builds
}
)=(
#{
created
}
) THEN 'created'
WHEN (
#{
builds
}
)=(
#{
preparing
}
) THEN 'preparing'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
) THEN 'success'
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
)+(
#{
canceled
}
) THEN 'canceled'
WHEN (
#{
builds
}
)=(
#{
created
}
)+(
#{
skipped
}
)+(
#{
pending
}
) THEN 'pending'
WHEN (
#{
running
}
)+(
#{
pending
}
)>0 THEN 'running'
WHEN (
#{
manual
}
)>0 THEN 'manual'
WHEN (
#{
scheduled
}
)>0 THEN 'scheduled'
WHEN (
#{
preparing
}
)>0 THEN 'preparing'
WHEN (
#{
created
}
)>0 THEN 'running'
ELSE 'failed'
END)"
)
end
def
legacy_status
all
.
pluck
(
legacy_status_sql
).
first
end
def
started_at
...
...
lib/gitlab/ci/status/composite_status.rb
View file @
35a464cc
...
...
@@ -5,36 +5,39 @@ module Gitlab
module
Status
class
CompositeStatus
def
initialize
(
all_statuses
)
@status_set
=
build_status_set
(
all_statuses
)
@warnings
=
false
@status_set
=
Set
.
new
build_status_set
(
all_statuses
)
end
def
status
case
when
only
?
(
:skipped
,
:warning
)
when
only
_of?
(
:skipped
)
&&
warnings?
:success
when
only?
(
:skipped
)
when
only
_of
?
(
:skipped
)
:skipped
when
only?
(
:success
)
:s
kipped
when
only?
(
:created
)
when
only
_of
?
(
:success
)
:s
uccess
when
only
_of
?
(
:created
)
:created
when
only?
(
:preparing
)
when
only
_of
?
(
:preparing
)
:preparing
when
only?
(
:success
,
:skipped
)
when
only
_of
?
(
:success
,
:skipped
)
:success
when
only?
(
:success
,
:skipped
,
:canceled
)
when
only
_of
?
(
:success
,
:skipped
,
:canceled
)
:canceled
when
only?
(
:created
,
:skipped
,
:pending
)
when
only
_of
?
(
:created
,
:skipped
,
:pending
)
:pending
when
include
?(
:running
,
:pending
)
when
any_of
?
(
:running
,
:pending
)
:running
when
include
?(
:manual
)
when
any_of
?
(
:manual
)
:manual
when
include
?(
:scheduled
)
when
any_of
?
(
:scheduled
)
:scheduled
when
include
?(
:preparing
)
when
any_of
?
(
:preparing
)
:preparing
when
include
?(
:created
)
when
any_of
?
(
:created
)
:running
else
:failed
...
...
@@ -42,31 +45,28 @@ module Gitlab
end
def
warnings?
include
?(
:warning
)
@warnings
end
private
def
include
?
(
*
names
)
def
any_of
?
(
*
names
)
names
.
any?
{
|
name
|
@status_set
.
include?
(
name
)
}
end
def
only?
(
*
names
)
matching
=
names
.
count
{
|
name
|
@status_set
.
include?
(
name
)
}
==
@status_set
.
size
def
only_of?
(
*
names
)
matching
=
names
.
count
{
|
name
|
@status_set
.
include?
(
name
)
}
matching
==
@status_set
.
size
end
def
build_status_set
(
all_statuses
)
status_set
=
Set
.
new
all_statuses
.
each
do
|
status
|
if
status
[
:allow_failure
]
&&
HasStatus
::
WARNING_STATUSES
.
include?
(
status
[
:status
])
status_set
.
add
(
:warning
)
@warnings
=
true
else
status_set
.
add
(
status
[
:status
].
to_sym
)
@
status_set
.
add
(
status
[
:status
].
to_sym
)
end
end
status_set
end
end
end
...
...
spec/models/concerns/has_status_spec.rb
View file @
35a464cc
...
...
@@ -3,12 +3,13 @@
require
'spec_helper'
describe
HasStatus
do
describe
'.status'
do
subject
{
CommitStatus
.
status
}
describe
'.
legacy_
status'
do
subject
{
CommitStatus
.
legacy_
status
}
shared_examples
'build status summary'
do
context
'all successful'
do
let!
(
:statuses
)
{
Array
.
new
(
2
)
{
create
(
type
,
status: :success
)
}
}
it
{
is_expected
.
to
eq
'success'
}
end
...
...
@@ -372,8 +373,8 @@ describe HasStatus do
end
end
describe
'.status_sql'
do
subject
{
Ci
::
Build
.
status_sql
}
describe
'.
legacy_
status_sql'
do
subject
{
Ci
::
Build
.
legacy_
status_sql
}
it
'returns SQL'
do
puts
subject
...
...
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