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
11ee48f3
Commit
11ee48f3
authored
Sep 30, 2019
by
Kamil Trzciński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix failures
parent
cba9eeb6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
33 additions
and
51 deletions
+33
-51
app/models/ci/group.rb
app/models/ci/group.rb
+4
-4
app/models/ci/legacy_stage.rb
app/models/ci/legacy_stage.rb
+7
-8
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-3
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+1
-6
lib/gitlab/ci/status/composite.rb
lib/gitlab/ci/status/composite.rb
+14
-8
spec/lib/gitlab/ci/status/composite_spec.rb
spec/lib/gitlab/ci/status/composite_spec.rb
+6
-13
spec/models/ci/legacy_stage_spec.rb
spec/models/ci/legacy_stage_spec.rb
+0
-9
No files found.
app/models/ci/group.rb
View file @
11ee48f3
...
@@ -24,13 +24,13 @@ module Ci
...
@@ -24,13 +24,13 @@ module Ci
def
status
def
status
strong_memoize
(
:status
)
do
strong_memoize
(
:status
)
do
if
Feature
.
enabled?
(
:ci_composite_status
,
default_enabled:
false
)
if
Feature
.
enabled?
(
:ci_composite_status
,
default_enabled:
false
)
all_statuses
=
@jobs
.
pluck
(
:status
,
:allow_failure
)
Gitlab
::
Ci
::
Status
::
Composite
Gitlab
::
Ci
::
Status
::
Composite
.
new
(
all_statuses
,
status_key:
0
,
allow_failure_key:
1
)
.
new
(
@jobs
)
.
status
.
status
else
else
CommitStatus
.
where
(
id:
@jobs
).
legacy_status
CommitStatus
.
where
(
id:
@jobs
)
.
legacy_status
end
end
end
end
end
end
...
...
app/models/ci/legacy_stage.rb
View file @
11ee48f3
...
@@ -14,7 +14,8 @@ module Ci
...
@@ -14,7 +14,8 @@ module Ci
@pipeline
=
pipeline
@pipeline
=
pipeline
@name
=
name
@name
=
name
@status
=
status
@status
=
status
@warnings
=
warnings
# support ints and booleans
@has_warnings
=
ActiveRecord
::
Type
::
Boolean
.
new
.
cast
(
warnings
)
end
end
def
groups
def
groups
...
@@ -52,14 +53,12 @@ module Ci
...
@@ -52,14 +53,12 @@ module Ci
end
end
def
has_warnings?
def
has_warnings?
case
@warnings
# lazilly calculate the warnings
when
Integer
if
@has_warnings
.
nil?
@warnings
>
0
@has_warnings
=
statuses
.
latest
.
failed_but_allowed
.
any?
when
TrueClass
,
FalseClass
@warnings
else
statuses
.
latest
.
failed_but_allowed
.
any?
end
end
@has_warnings
end
end
def
manual_playable?
def
manual_playable?
...
...
app/models/ci/pipeline.rb
View file @
11ee48f3
...
@@ -411,10 +411,8 @@ module Ci
...
@@ -411,10 +411,8 @@ module Ci
.
group_by
(
&
:stage
)
.
group_by
(
&
:stage
)
stages
.
map
do
|
stage_name
,
jobs
|
stages
.
map
do
|
stage_name
,
jobs
|
jobs_statuses
=
jobs
.
pluck
(
:status
,
:allow_failure
)
composite_status
=
Gitlab
::
Ci
::
Status
::
Composite
composite_status
=
Gitlab
::
Ci
::
Status
::
Composite
.
new
(
jobs
_statuses
,
status_key:
0
,
allow_failure_key:
1
)
.
new
(
jobs
)
Ci
::
LegacyStage
.
new
(
self
,
Ci
::
LegacyStage
.
new
(
self
,
name:
stage_name
,
name:
stage_name
,
...
...
app/models/concerns/has_status.rb
View file @
11ee48f3
...
@@ -65,13 +65,8 @@ module HasStatus
...
@@ -65,13 +65,8 @@ module HasStatus
# 2. Or executes expensive SQL query
# 2. Or executes expensive SQL query
def
slow_composite_status
def
slow_composite_status
if
Feature
.
enabled?
(
:ci_composite_status
,
default_enabled:
false
)
if
Feature
.
enabled?
(
:ci_composite_status
,
default_enabled:
false
)
columns
=
[
:status
]
columns
<<
:allow_failure
if
column_names
.
include?
(
'allow_failure'
)
all_statuses
=
all
.
pluck
(
*
columns
)
Gitlab
::
Ci
::
Status
::
Composite
Gitlab
::
Ci
::
Status
::
Composite
.
new
(
all
_statuses
,
status_key:
0
,
allow_failure_key:
1
)
.
new
(
all
,
with_allow_failure:
columns_hash
.
key?
(
'allow_failure'
)
)
.
status
.
status
else
else
legacy_status
legacy_status
...
...
lib/gitlab/ci/status/composite.rb
View file @
11ee48f3
...
@@ -6,15 +6,15 @@ module Gitlab
...
@@ -6,15 +6,15 @@ module Gitlab
class
Composite
class
Composite
include
Gitlab
::
Utils
::
StrongMemoize
include
Gitlab
::
Utils
::
StrongMemoize
# This class accepts an array of arrays
# This class accepts an array of arrays
/hashes/or objects
# The `status_key` and `allow_failure_key` define an index
def
initialize
(
all_statuses
,
with_allow_failure:
true
)
# or key in each entry
unless
all_statuses
.
respond_to?
(
:pluck
)
def
initialize
(
all_statuses
,
status_key
:,
allow_failure_key
:)
raise
ArgumentError
,
"all_statuses needs to respond to `.pluck`"
raise
ArgumentError
,
"all_statuses needs to be an Array"
unless
all_statuses
.
is_a?
(
Array
)
end
@status_set
=
Set
.
new
@status_set
=
Set
.
new
@status_key
=
status_key
@status_key
=
0
@allow_failure_key
=
allow_failure_key
@allow_failure_key
=
1
if
with_allow_failure
consume_all_statuses
(
all_statuses
)
consume_all_statuses
(
all_statuses
)
end
end
...
@@ -78,7 +78,13 @@ module Gitlab
...
@@ -78,7 +78,13 @@ module Gitlab
end
end
def
consume_all_statuses
(
all_statuses
)
def
consume_all_statuses
(
all_statuses
)
all_statuses
.
each
(
&
method
(
:consume_status
))
columns
=
[]
columns
[
@status_key
]
=
:status
columns
[
@allow_failure_key
]
=
:allow_failure
if
@allow_failure_key
all_statuses
.
pluck
(
*
columns
)
.
each
(
&
method
(
:consume_status
))
end
end
def
consume_status
(
description
)
def
consume_status
(
description
)
...
...
spec/lib/gitlab/ci/status/composite_spec.rb
View file @
11ee48f3
...
@@ -14,11 +14,12 @@ describe Gitlab::Ci::Status::Composite do
...
@@ -14,11 +14,12 @@ describe Gitlab::Ci::Status::Composite do
end
end
describe
'#status'
do
describe
'#status'
do
subject
{
composite_status
.
status
}
shared_examples
'compares composite with SQL status'
do
shared_examples
'compares composite with SQL status'
do
it
'returns exactly the same result'
do
it
'returns exactly the same result'
do
is_expected
.
to
eq
(
Ci
::
Build
.
where
(
id:
all_statuses
).
legacy_status
)
builds
=
Ci
::
Build
.
where
(
id:
all_statuses
)
expect
(
composite_status
.
status
).
to
eq
(
builds
.
legacy_status
)
expect
(
composite_status
.
warnings?
).
to
eq
(
builds
.
failed_but_allowed
.
any?
)
end
end
end
end
...
@@ -31,11 +32,7 @@ describe Gitlab::Ci::Status::Composite do
...
@@ -31,11 +32,7 @@ describe Gitlab::Ci::Status::Composite do
end
end
let
(
:composite_status
)
do
let
(
:composite_status
)
do
described_class
.
new
(
described_class
.
new
(
all_statuses
)
all_statuses
.
pluck
(
:status
),
status_key:
0
,
allow_failure_key:
nil
)
end
end
end
end
...
@@ -48,11 +45,7 @@ describe Gitlab::Ci::Status::Composite do
...
@@ -48,11 +45,7 @@ describe Gitlab::Ci::Status::Composite do
end
end
let
(
:composite_status
)
do
let
(
:composite_status
)
do
described_class
.
new
(
described_class
.
new
(
all_statuses
)
all_statuses
.
pluck
(
:status
,
:allow_failure
),
status_key:
0
,
allow_failure_key:
1
)
end
end
end
end
end
end
...
...
spec/models/ci/legacy_stage_spec.rb
View file @
11ee48f3
...
@@ -232,15 +232,6 @@ describe Ci::LegacyStage do
...
@@ -232,15 +232,6 @@ describe Ci::LegacyStage do
expect
(
stage
).
not_to
have_warnings
expect
(
stage
).
not_to
have_warnings
end
end
end
end
context
'when number of warnings is not a valid value'
do
let
(
:stage
)
{
build
(
:ci_stage
,
warnings:
'aa'
)
}
it
'calculates statuses using database queries'
do
expect
(
stage
).
to
receive
(
:statuses
).
and_call_original
expect
(
stage
).
not_to
have_warnings
end
end
end
end
context
'when calculating warnings from statuses'
do
context
'when calculating warnings from statuses'
do
...
...
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