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
Léo-Paul Géneau
gitlab-ce
Commits
cff9c16b
Commit
cff9c16b
authored
Jan 18, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pass memoizable warnings attribute to stage object
parent
ee18d89f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
13 deletions
+30
-13
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-5
app/models/ci/stage.rb
app/models/ci/stage.rb
+3
-2
spec/factories/ci/stages.rb
spec/factories/ci/stages.rb
+2
-1
spec/models/ci/stage_spec.rb
spec/models/ci/stage_spec.rb
+15
-5
No files found.
app/models/ci/pipeline.rb
View file @
cff9c16b
...
...
@@ -128,16 +128,21 @@ module Ci
end
def
stages
# TODO, this needs refactoring, see gitlab-ce#26481.
stages_query
=
statuses
.
group
(
'stage'
).
select
(
:stage
).
order
(
'max(stage_idx)'
)
status_sql
=
statuses
.
latest
.
where
(
'stage=sg.stage'
).
status_sql
stages_query
=
statuses
.
group
(
'stage'
).
select
(
:stage
)
.
order
(
'max(stage_idx)'
)
warnings_sql
=
statuses
.
latest
.
select
(
'COUNT(*) > 0'
)
.
where
(
'stage=sg.stage'
).
failed_but_allowed
.
to_sql
stages_with_statuses
=
CommitStatus
.
from
(
stages_query
,
:sg
)
.
pluck
(
'sg.stage'
,
status_sql
)
stages_with_statuses
=
CommitStatus
.
from
(
stages_query
,
:sg
)
.
pluck
(
'sg.stage'
,
status_sql
,
"(
#{
warnings_sql
}
)"
)
stages_with_statuses
.
map
do
|
stage
|
Ci
::
Stage
.
new
(
self
,
name:
stage
.
first
,
status:
stage
.
last
)
Ci
::
Stage
.
new
(
self
,
Hash
[
%i[name status warnings]
.
zip
(
stage
)]
)
end
end
...
...
app/models/ci/stage.rb
View file @
cff9c16b
...
...
@@ -8,10 +8,11 @@ module Ci
delegate
:project
,
to: :pipeline
def
initialize
(
pipeline
,
name
:,
status:
nil
)
def
initialize
(
pipeline
,
name
:,
status:
nil
,
warnings:
nil
)
@pipeline
=
pipeline
@name
=
name
@status
=
status
@warnings
=
warnings
end
def
to_param
...
...
@@ -45,7 +46,7 @@ module Ci
end
def
has_warnings?
statuses
.
latest
.
failed_but_allowed
.
any?
@warnings
||=
statuses
.
latest
.
failed_but_allowed
.
any?
end
end
end
spec/factories/ci/stages.rb
View file @
cff9c16b
...
...
@@ -3,11 +3,12 @@ FactoryGirl.define do
transient
do
name
'test'
status
nil
warnings
nil
pipeline
factory: :ci_empty_pipeline
end
initialize_with
do
Ci
::
Stage
.
new
(
pipeline
,
name:
name
,
status:
status
)
Ci
::
Stage
.
new
(
pipeline
,
name:
name
,
status:
status
,
warnings:
warnings
)
end
end
end
spec/models/ci/stage_spec.rb
View file @
cff9c16b
...
...
@@ -168,13 +168,23 @@ describe Ci::Stage, models: true do
describe
'#has_warnings?'
do
context
'when stage has warnings'
do
before
do
create
(
:ci_build
,
:failed
,
:allowed_to_fail
,
stage:
stage_name
,
pipeline:
pipeline
)
context
'when using memoized warnings flag'
do
let
(
:stage
)
{
build
(
:ci_stage
,
warnings:
true
)
}
it
'has warnings'
do
expect
(
stage
).
to
have_warnings
end
end
it
'has warnings'
do
expect
(
stage
).
to
have_warnings
context
'when calculating warnings from statuses'
do
before
do
create
(
:ci_build
,
:failed
,
:allowed_to_fail
,
stage:
stage_name
,
pipeline:
pipeline
)
end
it
'has warnings'
do
expect
(
stage
).
to
have_warnings
end
end
end
...
...
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