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
af84cfef
Commit
af84cfef
authored
Jun 22, 2020
by
blackst0ne
Committed by
Dmytro Zaporozhets
Jun 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move HasStatus module to the Ci namespace
parent
bf23553c
Changes
30
Show whitespace changes
Inline
Side-by-side
Showing
30 changed files
with
214 additions
and
207 deletions
+214
-207
app/finders/ci/pipelines_finder.rb
app/finders/ci/pipelines_finder.rb
+1
-1
app/finders/ci/runner_jobs_finder.rb
app/finders/ci/runner_jobs_finder.rb
+1
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+2
-2
app/models/ci/stage.rb
app/models/ci/stage.rb
+3
-3
app/models/commit_status.rb
app/models/commit_status.rb
+1
-1
app/models/concerns/ci/has_status.rb
app/models/concerns/ci/has_status.rb
+168
-0
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+0
-166
app/models/environment.rb
app/models/environment.rb
+1
-1
app/serializers/stage_entity.rb
app/serializers/stage_entity.rb
+2
-2
app/services/ci/pipeline_processing/atomic_processing_service.rb
...vices/ci/pipeline_processing/atomic_processing_service.rb
+1
-1
app/services/ci/pipeline_processing/atomic_processing_service/status_collection.rb
...processing/atomic_processing_service/status_collection.rb
+1
-1
app/services/ci/pipeline_processing/legacy_processing_service.rb
...vices/ci/pipeline_processing/legacy_processing_service.rb
+2
-2
app/views/projects/pipelines/_stage.html.haml
app/views/projects/pipelines/_stage.html.haml
+1
-1
changelogs/unreleased/move-has-status-concern-to-ci-namespace.yml
...gs/unreleased/move-has-status-concern-to-ci-namespace.yml
+5
-0
lib/api/pipelines.rb
lib/api/pipelines.rb
+1
-1
lib/gitlab/ci/status/composite.rb
lib/gitlab/ci/status/composite.rb
+2
-2
lib/gitlab/ci/status/factory.rb
lib/gitlab/ci/status/factory.rb
+1
-1
spec/finders/ci/pipelines_finder_spec.rb
spec/finders/ci/pipelines_finder_spec.rb
+2
-2
spec/finders/ci/runner_jobs_finder_spec.rb
spec/finders/ci/runner_jobs_finder_spec.rb
+2
-2
spec/lib/gitlab/auth_spec.rb
spec/lib/gitlab/auth_spec.rb
+1
-1
spec/lib/gitlab/ci/status/composite_spec.rb
spec/lib/gitlab/ci/status/composite_spec.rb
+4
-4
spec/lib/gitlab/ci/status/external/factory_spec.rb
spec/lib/gitlab/ci/status/external/factory_spec.rb
+1
-1
spec/lib/gitlab/ci/status/factory_spec.rb
spec/lib/gitlab/ci/status/factory_spec.rb
+1
-1
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
+1
-1
spec/lib/gitlab/ci/status/stage/factory_spec.rb
spec/lib/gitlab/ci/status/stage/factory_spec.rb
+2
-2
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-1
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+1
-1
spec/models/concerns/ci/has_status_spec.rb
spec/models/concerns/ci/has_status_spec.rb
+1
-1
spec/requests/api/pipelines_spec.rb
spec/requests/api/pipelines_spec.rb
+2
-2
spec/views/projects/pipelines/_stage.html.haml_spec.rb
spec/views/projects/pipelines/_stage.html.haml_spec.rb
+2
-2
No files found.
app/finders/ci/pipelines_finder.rb
View file @
af84cfef
...
...
@@ -71,7 +71,7 @@ module Ci
# rubocop: disable CodeReuse/ActiveRecord
def
by_status
(
items
)
return
items
unless
HasStatus
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
return
items
unless
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
items
.
where
(
status:
params
[
:status
])
end
...
...
app/finders/ci/runner_jobs_finder.rb
View file @
af84cfef
...
...
@@ -21,7 +21,7 @@ module Ci
# rubocop: disable CodeReuse/ActiveRecord
def
by_status
(
items
)
return
items
unless
HasStatus
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
return
items
unless
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
include?
(
params
[
:status
])
items
.
where
(
status:
params
[
:status
])
end
...
...
app/models/ci/pipeline.rb
View file @
af84cfef
...
...
@@ -3,7 +3,7 @@
module
Ci
class
Pipeline
<
ApplicationRecord
extend
Gitlab
::
Ci
::
Model
include
HasStatus
include
Ci
::
HasStatus
include
Importable
include
AfterCommitQueue
include
Presentable
...
...
@@ -640,7 +640,7 @@ module Ci
when
'manual'
then
block
when
'scheduled'
then
delay
else
raise
HasStatus
::
UnknownStatusError
,
raise
Ci
::
HasStatus
::
UnknownStatusError
,
"Unknown status `
#{
new_status
}
`"
end
end
...
...
app/models/ci/stage.rb
View file @
af84cfef
...
...
@@ -4,10 +4,10 @@ module Ci
class
Stage
<
ApplicationRecord
extend
Gitlab
::
Ci
::
Model
include
Importable
include
HasStatus
include
Ci
::
HasStatus
include
Gitlab
::
OptimisticLocking
enum
status:
HasStatus
::
STATUSES_ENUM
enum
status:
Ci
::
HasStatus
::
STATUSES_ENUM
belongs_to
:project
belongs_to
:pipeline
...
...
@@ -98,7 +98,7 @@ module Ci
when
'scheduled'
then
delay
when
'skipped'
,
nil
then
skip
else
raise
HasStatus
::
UnknownStatusError
,
raise
Ci
::
HasStatus
::
UnknownStatusError
,
"Unknown status `
#{
new_status
}
`"
end
end
...
...
app/models/commit_status.rb
View file @
af84cfef
# frozen_string_literal: true
class
CommitStatus
<
ApplicationRecord
include
HasStatus
include
Ci
::
HasStatus
include
Importable
include
AfterCommitQueue
include
Presentable
...
...
app/models/concerns/ci/has_status.rb
0 → 100644
View file @
af84cfef
# frozen_string_literal: true
module
Ci
module
HasStatus
extend
ActiveSupport
::
Concern
DEFAULT_STATUS
=
'created'
BLOCKED_STATUS
=
%w[manual scheduled]
.
freeze
AVAILABLE_STATUSES
=
%w[created waiting_for_resource preparing pending running success failed canceled skipped manual scheduled]
.
freeze
STARTED_STATUSES
=
%w[running success failed skipped manual scheduled]
.
freeze
ACTIVE_STATUSES
=
%w[waiting_for_resource preparing pending running]
.
freeze
COMPLETED_STATUSES
=
%w[success failed canceled skipped]
.
freeze
ORDERED_STATUSES
=
%w[failed preparing pending running waiting_for_resource manual scheduled canceled success skipped created]
.
freeze
PASSED_WITH_WARNINGS_STATUSES
=
%w[failed canceled]
.
to_set
.
freeze
EXCLUDE_IGNORED_STATUSES
=
%w[manual failed canceled]
.
to_set
.
freeze
STATUSES_ENUM
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
,
scheduled:
8
,
preparing:
9
,
waiting_for_resource:
10
}.
freeze
UnknownStatusError
=
Class
.
new
(
StandardError
)
class_methods
do
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
waiting_for_resource
=
scope_relevant
.
waiting_for_resource
.
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 (
#{
waiting_for_resource
}
)>0 THEN 'waiting_for_resource'
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
# This method should not be used.
# This method performs expensive calculation of status:
# 1. By plucking all related objects,
# 2. Or executes expensive SQL query
def
slow_composite_status
(
project
:)
if
::
Gitlab
::
Ci
::
Features
.
composite_status?
(
project
)
Gitlab
::
Ci
::
Status
::
Composite
.
new
(
all
,
with_allow_failure:
columns_hash
.
key?
(
'allow_failure'
))
.
status
else
legacy_status
end
end
def
started_at
all
.
minimum
(
:started_at
)
end
def
finished_at
all
.
maximum
(
:finished_at
)
end
def
all_state_names
state_machines
.
values
.
flat_map
(
&
:states
).
flat_map
{
|
s
|
s
.
map
(
&
:name
)
}
end
def
completed_statuses
COMPLETED_STATUSES
.
map
(
&
:to_sym
)
end
end
included
do
validates
:status
,
inclusion:
{
in:
AVAILABLE_STATUSES
}
state_machine
:status
,
initial: :created
do
state
:created
,
value:
'created'
state
:waiting_for_resource
,
value:
'waiting_for_resource'
state
:preparing
,
value:
'preparing'
state
:pending
,
value:
'pending'
state
:running
,
value:
'running'
state
:failed
,
value:
'failed'
state
:success
,
value:
'success'
state
:canceled
,
value:
'canceled'
state
:skipped
,
value:
'skipped'
state
:manual
,
value:
'manual'
state
:scheduled
,
value:
'scheduled'
end
scope
:created
,
->
{
with_status
(
:created
)
}
scope
:waiting_for_resource
,
->
{
with_status
(
:waiting_for_resource
)
}
scope
:preparing
,
->
{
with_status
(
:preparing
)
}
scope
:relevant
,
->
{
without_status
(
:created
)
}
scope
:running
,
->
{
with_status
(
:running
)
}
scope
:pending
,
->
{
with_status
(
:pending
)
}
scope
:success
,
->
{
with_status
(
:success
)
}
scope
:failed
,
->
{
with_status
(
:failed
)
}
scope
:canceled
,
->
{
with_status
(
:canceled
)
}
scope
:skipped
,
->
{
with_status
(
:skipped
)
}
scope
:manual
,
->
{
with_status
(
:manual
)
}
scope
:scheduled
,
->
{
with_status
(
:scheduled
)
}
scope
:alive
,
->
{
with_status
(
:created
,
:waiting_for_resource
,
:preparing
,
:pending
,
:running
)
}
scope
:alive_or_scheduled
,
->
{
with_status
(
:created
,
:waiting_for_resource
,
:preparing
,
:pending
,
:running
,
:scheduled
)
}
scope
:created_or_pending
,
->
{
with_status
(
:created
,
:pending
)
}
scope
:running_or_pending
,
->
{
with_status
(
:running
,
:pending
)
}
scope
:finished
,
->
{
with_status
(
:success
,
:failed
,
:canceled
)
}
scope
:failed_or_canceled
,
->
{
with_status
(
:failed
,
:canceled
)
}
scope
:incomplete
,
->
{
without_statuses
(
completed_statuses
)
}
scope
:cancelable
,
->
do
where
(
status:
[
:running
,
:waiting_for_resource
,
:preparing
,
:pending
,
:created
,
:scheduled
])
end
scope
:without_statuses
,
->
(
names
)
do
with_status
(
all_state_names
-
names
.
to_a
)
end
end
def
started?
STARTED_STATUSES
.
include?
(
status
)
&&
started_at
end
def
active?
ACTIVE_STATUSES
.
include?
(
status
)
end
def
complete?
COMPLETED_STATUSES
.
include?
(
status
)
end
def
blocked?
BLOCKED_STATUS
.
include?
(
status
)
end
private
def
calculate_duration
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
current
-
started_at
end
end
end
end
app/models/concerns/has_status.rb
deleted
100644 → 0
View file @
bf23553c
# frozen_string_literal: true
module
HasStatus
extend
ActiveSupport
::
Concern
DEFAULT_STATUS
=
'created'
BLOCKED_STATUS
=
%w[manual scheduled]
.
freeze
AVAILABLE_STATUSES
=
%w[created waiting_for_resource preparing pending running success failed canceled skipped manual scheduled]
.
freeze
STARTED_STATUSES
=
%w[running success failed skipped manual scheduled]
.
freeze
ACTIVE_STATUSES
=
%w[waiting_for_resource preparing pending running]
.
freeze
COMPLETED_STATUSES
=
%w[success failed canceled skipped]
.
freeze
ORDERED_STATUSES
=
%w[failed preparing pending running waiting_for_resource manual scheduled canceled success skipped created]
.
freeze
PASSED_WITH_WARNINGS_STATUSES
=
%w[failed canceled]
.
to_set
.
freeze
EXCLUDE_IGNORED_STATUSES
=
%w[manual failed canceled]
.
to_set
.
freeze
STATUSES_ENUM
=
{
created:
0
,
pending:
1
,
running:
2
,
success:
3
,
failed:
4
,
canceled:
5
,
skipped:
6
,
manual:
7
,
scheduled:
8
,
preparing:
9
,
waiting_for_resource:
10
}.
freeze
UnknownStatusError
=
Class
.
new
(
StandardError
)
class_methods
do
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
waiting_for_resource
=
scope_relevant
.
waiting_for_resource
.
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 (
#{
waiting_for_resource
}
)>0 THEN 'waiting_for_resource'
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
# This method should not be used.
# This method performs expensive calculation of status:
# 1. By plucking all related objects,
# 2. Or executes expensive SQL query
def
slow_composite_status
(
project
:)
if
::
Gitlab
::
Ci
::
Features
.
composite_status?
(
project
)
Gitlab
::
Ci
::
Status
::
Composite
.
new
(
all
,
with_allow_failure:
columns_hash
.
key?
(
'allow_failure'
))
.
status
else
legacy_status
end
end
def
started_at
all
.
minimum
(
:started_at
)
end
def
finished_at
all
.
maximum
(
:finished_at
)
end
def
all_state_names
state_machines
.
values
.
flat_map
(
&
:states
).
flat_map
{
|
s
|
s
.
map
(
&
:name
)
}
end
def
completed_statuses
COMPLETED_STATUSES
.
map
(
&
:to_sym
)
end
end
included
do
validates
:status
,
inclusion:
{
in:
AVAILABLE_STATUSES
}
state_machine
:status
,
initial: :created
do
state
:created
,
value:
'created'
state
:waiting_for_resource
,
value:
'waiting_for_resource'
state
:preparing
,
value:
'preparing'
state
:pending
,
value:
'pending'
state
:running
,
value:
'running'
state
:failed
,
value:
'failed'
state
:success
,
value:
'success'
state
:canceled
,
value:
'canceled'
state
:skipped
,
value:
'skipped'
state
:manual
,
value:
'manual'
state
:scheduled
,
value:
'scheduled'
end
scope
:created
,
->
{
with_status
(
:created
)
}
scope
:waiting_for_resource
,
->
{
with_status
(
:waiting_for_resource
)
}
scope
:preparing
,
->
{
with_status
(
:preparing
)
}
scope
:relevant
,
->
{
without_status
(
:created
)
}
scope
:running
,
->
{
with_status
(
:running
)
}
scope
:pending
,
->
{
with_status
(
:pending
)
}
scope
:success
,
->
{
with_status
(
:success
)
}
scope
:failed
,
->
{
with_status
(
:failed
)
}
scope
:canceled
,
->
{
with_status
(
:canceled
)
}
scope
:skipped
,
->
{
with_status
(
:skipped
)
}
scope
:manual
,
->
{
with_status
(
:manual
)
}
scope
:scheduled
,
->
{
with_status
(
:scheduled
)
}
scope
:alive
,
->
{
with_status
(
:created
,
:waiting_for_resource
,
:preparing
,
:pending
,
:running
)
}
scope
:alive_or_scheduled
,
->
{
with_status
(
:created
,
:waiting_for_resource
,
:preparing
,
:pending
,
:running
,
:scheduled
)
}
scope
:created_or_pending
,
->
{
with_status
(
:created
,
:pending
)
}
scope
:running_or_pending
,
->
{
with_status
(
:running
,
:pending
)
}
scope
:finished
,
->
{
with_status
(
:success
,
:failed
,
:canceled
)
}
scope
:failed_or_canceled
,
->
{
with_status
(
:failed
,
:canceled
)
}
scope
:incomplete
,
->
{
without_statuses
(
completed_statuses
)
}
scope
:cancelable
,
->
do
where
(
status:
[
:running
,
:waiting_for_resource
,
:preparing
,
:pending
,
:created
,
:scheduled
])
end
scope
:without_statuses
,
->
(
names
)
do
with_status
(
all_state_names
-
names
.
to_a
)
end
end
def
started?
STARTED_STATUSES
.
include?
(
status
)
&&
started_at
end
def
active?
ACTIVE_STATUSES
.
include?
(
status
)
end
def
complete?
COMPLETED_STATUSES
.
include?
(
status
)
end
def
blocked?
BLOCKED_STATUS
.
include?
(
status
)
end
private
def
calculate_duration
if
started_at
&&
finished_at
finished_at
-
started_at
elsif
started_at
Time
.
current
-
started_at
end
end
end
app/models/environment.rb
View file @
af84cfef
...
...
@@ -147,7 +147,7 @@ class Environment < ApplicationRecord
Ci
::
Build
.
joins
(
inner_join_stop_actions
)
.
with
(
cte
.
to_arel
)
.
where
(
ci_builds
[
:commit_id
].
in
(
pipeline_ids
))
.
where
(
status:
HasStatus
::
BLOCKED_STATUS
)
.
where
(
status:
Ci
::
HasStatus
::
BLOCKED_STATUS
)
.
preload_project_and_pipeline_project
.
preload
(
:user
,
:metadata
,
:deployment
)
end
...
...
app/serializers/stage_entity.rb
View file @
af84cfef
...
...
@@ -59,13 +59,13 @@ class StageEntity < Grape::Entity
end
def
latest_statuses
HasStatus
::
ORDERED_STATUSES
.
flat_map
do
|
ordered_status
|
Ci
::
HasStatus
::
ORDERED_STATUSES
.
flat_map
do
|
ordered_status
|
grouped_statuses
.
fetch
(
ordered_status
,
[])
end
end
def
retried_statuses
HasStatus
::
ORDERED_STATUSES
.
flat_map
do
|
ordered_status
|
Ci
::
HasStatus
::
ORDERED_STATUSES
.
flat_map
do
|
ordered_status
|
grouped_retried_statuses
.
fetch
(
ordered_status
,
[])
end
end
...
...
app/services/ci/pipeline_processing/atomic_processing_service.rb
View file @
af84cfef
...
...
@@ -77,7 +77,7 @@ module Ci
def
update_processable!
(
processable
)
status
=
processable_status
(
processable
)
return
unless
HasStatus
::
COMPLETED_STATUSES
.
include?
(
status
)
return
unless
Ci
::
HasStatus
::
COMPLETED_STATUSES
.
include?
(
status
)
# transition status if possible
Gitlab
::
OptimisticLocking
.
retry_lock
(
processable
)
do
|
subject
|
...
...
app/services/ci/pipeline_processing/atomic_processing_service/status_collection.rb
View file @
af84cfef
...
...
@@ -80,7 +80,7 @@ module Ci
# TODO: This is hack to support
# the same exact behaviour for Atomic and Legacy processing
# that DAG is blocked from executing if dependent is not "complete"
if
dag
&&
statuses
.
any?
{
|
status
|
HasStatus
::
COMPLETED_STATUSES
.
exclude?
(
status
[
:status
])
}
if
dag
&&
statuses
.
any?
{
|
status
|
Ci
::
HasStatus
::
COMPLETED_STATUSES
.
exclude?
(
status
[
:status
])
}
return
'pending'
end
...
...
app/services/ci/pipeline_processing/legacy_processing_service.rb
View file @
af84cfef
...
...
@@ -35,7 +35,7 @@ module Ci
def
process_stage_for_stage_scheduling
(
index
)
current_status
=
status_for_prior_stages
(
index
)
return
unless
HasStatus
::
COMPLETED_STATUSES
.
include?
(
current_status
)
return
unless
Ci
::
HasStatus
::
COMPLETED_STATUSES
.
include?
(
current_status
)
created_stage_scheduled_processables_in_stage
(
index
).
find_each
.
select
do
|
build
|
process_build
(
build
,
current_status
)
...
...
@@ -73,7 +73,7 @@ module Ci
def
process_dag_build_with_needs
(
build
)
current_status
=
status_for_build_needs
(
build
.
needs
.
map
(
&
:name
))
return
unless
HasStatus
::
COMPLETED_STATUSES
.
include?
(
current_status
)
return
unless
Ci
::
HasStatus
::
COMPLETED_STATUSES
.
include?
(
current_status
)
process_build
(
build
,
current_status
)
end
...
...
app/views/projects/pipelines/_stage.html.haml
View file @
af84cfef
-
grouped_statuses
=
@stage
.
statuses
.
latest_ordered
.
group_by
(
&
:status
)
-
HasStatus
::
ORDERED_STATUSES
.
each
do
|
ordered_status
|
-
Ci
::
HasStatus
::
ORDERED_STATUSES
.
each
do
|
ordered_status
|
-
grouped_statuses
.
fetch
(
ordered_status
,
[]).
each
do
|
status
|
%li
=
render
'ci/status/dropdown_graph_badge'
,
subject:
status
changelogs/unreleased/move-has-status-concern-to-ci-namespace.yml
0 → 100644
View file @
af84cfef
---
title
:
Move HasStatus module to the Ci namespace
merge_request
:
34577
author
:
blackst0ne
type
:
other
lib/api/pipelines.rb
View file @
af84cfef
...
...
@@ -18,7 +18,7 @@ module API
use
:pagination
optional
:scope
,
type:
String
,
values:
%w[running pending finished branches tags]
,
desc:
'The scope of pipelines'
optional
:status
,
type:
String
,
values:
HasStatus
::
AVAILABLE_STATUSES
,
optional
:status
,
type:
String
,
values:
Ci
::
HasStatus
::
AVAILABLE_STATUSES
,
desc:
'The status of pipelines'
optional
:ref
,
type:
String
,
desc:
'The ref of pipelines'
optional
:sha
,
type:
String
,
desc:
'The sha of pipelines'
...
...
lib/gitlab/ci/status/composite.rb
View file @
af84cfef
...
...
@@ -112,13 +112,13 @@ module Gitlab
def
success_with_warnings?
(
status
)
@allow_failure_key
&&
status
[
@allow_failure_key
]
&&
HasStatus
::
PASSED_WITH_WARNINGS_STATUSES
.
include?
(
status
[
@status_key
])
::
Ci
::
HasStatus
::
PASSED_WITH_WARNINGS_STATUSES
.
include?
(
status
[
@status_key
])
end
def
ignored_status?
(
status
)
@allow_failure_key
&&
status
[
@allow_failure_key
]
&&
HasStatus
::
EXCLUDE_IGNORED_STATUSES
.
include?
(
status
[
@status_key
])
::
Ci
::
HasStatus
::
EXCLUDE_IGNORED_STATUSES
.
include?
(
status
[
@status_key
])
end
end
end
...
...
lib/gitlab/ci/status/factory.rb
View file @
af84cfef
...
...
@@ -7,7 +7,7 @@ module Gitlab
def
initialize
(
subject
,
user
)
@subject
=
subject
@user
=
user
@status
=
subject
.
status
||
HasStatus
::
DEFAULT_STATUS
@status
=
subject
.
status
||
::
Ci
::
HasStatus
::
DEFAULT_STATUS
end
def
fabricate!
...
...
spec/finders/ci/pipelines_finder_spec.rb
View file @
af84cfef
...
...
@@ -77,13 +77,13 @@ RSpec.describe Ci::PipelinesFinder do
end
end
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target
|
context
"when status is
#{
target
}
"
do
let
(
:params
)
{
{
status:
target
}
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
status:
target
)
}
before
do
exception_status
=
HasStatus
::
AVAILABLE_STATUSES
-
[
target
]
exception_status
=
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
[
target
]
create
(
:ci_pipeline
,
project:
project
,
status:
exception_status
.
first
)
end
...
...
spec/finders/ci/runner_jobs_finder_spec.rb
View file @
af84cfef
...
...
@@ -21,13 +21,13 @@ RSpec.describe Ci::RunnerJobsFinder do
end
context
'when params contains status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target_status
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target_status
|
context
"when status is
#{
target_status
}
"
do
let
(
:params
)
{
{
status:
target_status
}
}
let!
(
:job
)
{
create
(
:ci_build
,
runner:
runner
,
project:
project
,
status:
target_status
)
}
before
do
exception_status
=
HasStatus
::
AVAILABLE_STATUSES
-
[
target_status
]
exception_status
=
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
[
target_status
]
create
(
:ci_build
,
runner:
runner
,
project:
project
,
status:
exception_status
.
first
)
end
...
...
spec/lib/gitlab/auth_spec.rb
View file @
af84cfef
...
...
@@ -172,7 +172,7 @@ describe Gitlab::Auth, :use_clean_rails_memory_store_caching do
end
end
(
HasStatus
::
AVAILABLE_STATUSES
-
[
'running'
]).
each
do
|
build_status
|
(
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
[
'running'
]).
each
do
|
build_status
|
context
"for
#{
build_status
}
build"
do
let!
(
:build
)
{
create
(
:ci_build
,
status:
build_status
)
}
let
(
:project
)
{
build
.
project
}
...
...
spec/lib/gitlab/ci/status/composite_spec.rb
View file @
af84cfef
...
...
@@ -6,11 +6,11 @@ describe Gitlab::Ci::Status::Composite do
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
before_all
do
@statuses
=
HasStatus
::
STATUSES_ENUM
.
map
do
|
status
,
idx
|
@statuses
=
Ci
::
HasStatus
::
STATUSES_ENUM
.
map
do
|
status
,
idx
|
[
status
,
create
(
:ci_build
,
pipeline:
pipeline
,
status:
status
,
importing:
true
)]
end
.
to_h
@statuses_with_allow_failure
=
HasStatus
::
STATUSES_ENUM
.
map
do
|
status
,
idx
|
@statuses_with_allow_failure
=
Ci
::
HasStatus
::
STATUSES_ENUM
.
map
do
|
status
,
idx
|
[
status
,
create
(
:ci_build
,
pipeline:
pipeline
,
status:
status
,
allow_failure:
true
,
importing:
true
)]
end
.
to_h
end
...
...
@@ -26,7 +26,7 @@ describe Gitlab::Ci::Status::Composite do
end
shared_examples
'validate all combinations'
do
|
perms
|
HasStatus
::
STATUSES_ENUM
.
keys
.
combination
(
perms
).
each
do
|
statuses
|
Ci
::
HasStatus
::
STATUSES_ENUM
.
keys
.
combination
(
perms
).
each
do
|
statuses
|
context
"with
#{
statuses
.
join
(
","
)
}
"
do
it_behaves_like
'compares composite with SQL status'
do
let
(
:all_statuses
)
do
...
...
@@ -38,7 +38,7 @@ describe Gitlab::Ci::Status::Composite do
end
end
HasStatus
::
STATUSES_ENUM
.
each
do
|
allow_failure_status
,
_
|
Ci
::
HasStatus
::
STATUSES_ENUM
.
each
do
|
allow_failure_status
,
_
|
context
"and allow_failure
#{
allow_failure_status
}
"
do
it_behaves_like
'compares composite with SQL status'
do
let
(
:all_statuses
)
do
...
...
spec/lib/gitlab/ci/status/external/factory_spec.rb
View file @
af84cfef
...
...
@@ -14,7 +14,7 @@ describe Gitlab::Ci::Status::External::Factory do
end
context
'when external status has a simple core status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
simple_status
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
simple_status
|
context
"when core status is
#{
simple_status
}
"
do
let
(
:resource
)
do
create
(
:generic_commit_status
,
status:
simple_status
,
...
...
spec/lib/gitlab/ci/status/factory_spec.rb
View file @
af84cfef
...
...
@@ -8,7 +8,7 @@ describe Gitlab::Ci::Status::Factory do
let
(
:factory
)
{
described_class
.
new
(
resource
,
user
)
}
context
'when object has a core status'
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
simple_status
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
simple_status
|
context
"when simple core status is
#{
simple_status
}
"
do
let
(
:resource
)
{
double
(
'resource'
,
status:
simple_status
)
}
...
...
spec/lib/gitlab/ci/status/pipeline/factory_spec.rb
View file @
af84cfef
...
...
@@ -13,7 +13,7 @@ describe Gitlab::Ci::Status::Pipeline::Factory do
end
context
'when pipeline has a core status'
do
(
HasStatus
::
AVAILABLE_STATUSES
-
HasStatus
::
BLOCKED_STATUS
).
each
do
|
simple_status
|
(
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
Ci
::
HasStatus
::
BLOCKED_STATUS
).
each
do
|
simple_status
|
context
"when core status is
#{
simple_status
}
"
do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
status:
simple_status
)
}
...
...
spec/lib/gitlab/ci/status/stage/factory_spec.rb
View file @
af84cfef
...
...
@@ -24,7 +24,7 @@ describe Gitlab::Ci::Status::Stage::Factory do
end
context
'when stage has a core status'
do
(
HasStatus
::
AVAILABLE_STATUSES
-
%w(manual skipped scheduled)
).
each
do
|
core_status
|
(
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
%w(manual skipped scheduled)
).
each
do
|
core_status
|
context
"when core status is
#{
core_status
}
"
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'test'
,
status:
core_status
)
...
...
@@ -68,7 +68,7 @@ describe Gitlab::Ci::Status::Stage::Factory do
end
context
'when stage has manual builds'
do
(
HasStatus
::
BLOCKED_STATUS
+
[
'skipped'
]).
each
do
|
core_status
|
(
Ci
::
HasStatus
::
BLOCKED_STATUS
+
[
'skipped'
]).
each
do
|
core_status
|
context
"when status is
#{
core_status
}
"
do
before
do
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'test'
,
status:
core_status
)
...
...
spec/models/ci/pipeline_spec.rb
View file @
af84cfef
...
...
@@ -2087,7 +2087,7 @@ describe Ci::Pipeline, :mailer do
it
'raises an exception'
do
expect
{
pipeline
.
update_legacy_status
}
.
to
raise_error
(
HasStatus
::
UnknownStatusError
)
.
to
raise_error
(
Ci
::
HasStatus
::
UnknownStatusError
)
end
end
end
...
...
spec/models/ci/stage_spec.rb
View file @
af84cfef
...
...
@@ -172,7 +172,7 @@ describe Ci::Stage, :models do
it
'raises an exception'
do
expect
{
stage
.
update_legacy_status
}
.
to
raise_error
(
HasStatus
::
UnknownStatusError
)
.
to
raise_error
(
Ci
::
HasStatus
::
UnknownStatusError
)
end
end
end
...
...
spec/models/concerns/has_status_spec.rb
→
spec/models/concerns/
ci/
has_status_spec.rb
View file @
af84cfef
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
describe
HasStatus
do
describe
Ci
::
HasStatus
do
describe
'.slow_composite_status'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
spec/requests/api/pipelines_spec.rb
View file @
af84cfef
...
...
@@ -106,11 +106,11 @@ describe API::Pipelines do
end
end
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
target
|
context
"when status is
#{
target
}
"
do
before
do
create
(
:ci_pipeline
,
project:
project
,
status:
target
)
exception_status
=
HasStatus
::
AVAILABLE_STATUSES
-
[
target
]
exception_status
=
Ci
::
HasStatus
::
AVAILABLE_STATUSES
-
[
target
]
create
(
:ci_pipeline
,
project:
project
,
status:
exception_status
.
sample
)
end
...
...
spec/views/projects/pipelines/_stage.html.haml_spec.rb
View file @
af84cfef
...
...
@@ -54,7 +54,7 @@ describe 'projects/pipelines/_stage' do
context
'when there are multiple builds'
do
before
do
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
status
|
Ci
::
HasStatus
::
AVAILABLE_STATUSES
.
each
do
|
status
|
create_build
(
status
)
end
end
...
...
@@ -62,7 +62,7 @@ describe 'projects/pipelines/_stage' do
it
'shows them in order'
do
render
expect
(
rendered
).
to
have_text
(
HasStatus
::
ORDERED_STATUSES
.
join
(
" "
))
expect
(
rendered
).
to
have_text
(
Ci
::
HasStatus
::
ORDERED_STATUSES
.
join
(
" "
))
end
def
create_build
(
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