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
Tatuya Kamada
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
Show 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
...
@@ -128,16 +128,21 @@ module Ci
end
end
def
stages
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
status_sql
=
statuses
.
latest
.
where
(
'stage=sg.stage'
).
status_sql
stages_query
=
statuses
.
group
(
'stage'
).
select
(
:stage
)
warnings_sql
=
statuses
.
latest
.
select
(
'COUNT(*) > 0'
)
.
order
(
'max(stage_idx)'
)
.
where
(
'stage=sg.stage'
).
failed_but_allowed
.
to_sql
stages_with_statuses
=
CommitStatus
.
from
(
stages_query
,
:sg
)
.
stages_with_statuses
=
CommitStatus
.
from
(
stages_query
,
:sg
)
pluck
(
'sg.stage'
,
status_sql
)
.
pluck
(
'sg.stage'
,
status_sql
,
"(
#{
warnings_sql
}
)"
)
stages_with_statuses
.
map
do
|
stage
|
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
end
end
...
...
app/models/ci/stage.rb
View file @
cff9c16b
...
@@ -8,10 +8,11 @@ module Ci
...
@@ -8,10 +8,11 @@ module Ci
delegate
:project
,
to: :pipeline
delegate
:project
,
to: :pipeline
def
initialize
(
pipeline
,
name
:,
status:
nil
)
def
initialize
(
pipeline
,
name
:,
status:
nil
,
warnings:
nil
)
@pipeline
=
pipeline
@pipeline
=
pipeline
@name
=
name
@name
=
name
@status
=
status
@status
=
status
@warnings
=
warnings
end
end
def
to_param
def
to_param
...
@@ -45,7 +46,7 @@ module Ci
...
@@ -45,7 +46,7 @@ module Ci
end
end
def
has_warnings?
def
has_warnings?
statuses
.
latest
.
failed_but_allowed
.
any?
@warnings
||=
statuses
.
latest
.
failed_but_allowed
.
any?
end
end
end
end
end
end
spec/factories/ci/stages.rb
View file @
cff9c16b
...
@@ -3,11 +3,12 @@ FactoryGirl.define do
...
@@ -3,11 +3,12 @@ FactoryGirl.define do
transient
do
transient
do
name
'test'
name
'test'
status
nil
status
nil
warnings
nil
pipeline
factory: :ci_empty_pipeline
pipeline
factory: :ci_empty_pipeline
end
end
initialize_with
do
initialize_with
do
Ci
::
Stage
.
new
(
pipeline
,
name:
name
,
status:
status
)
Ci
::
Stage
.
new
(
pipeline
,
name:
name
,
status:
status
,
warnings:
warnings
)
end
end
end
end
end
end
spec/models/ci/stage_spec.rb
View file @
cff9c16b
...
@@ -168,6 +168,15 @@ describe Ci::Stage, models: true do
...
@@ -168,6 +168,15 @@ describe Ci::Stage, models: true do
describe
'#has_warnings?'
do
describe
'#has_warnings?'
do
context
'when stage has warnings'
do
context
'when stage has warnings'
do
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
context
'when calculating warnings from statuses'
do
before
do
before
do
create
(
:ci_build
,
:failed
,
:allowed_to_fail
,
create
(
:ci_build
,
:failed
,
:allowed_to_fail
,
stage:
stage_name
,
pipeline:
pipeline
)
stage:
stage_name
,
pipeline:
pipeline
)
...
@@ -177,6 +186,7 @@ describe Ci::Stage, models: true do
...
@@ -177,6 +186,7 @@ describe Ci::Stage, models: true do
expect
(
stage
).
to
have_warnings
expect
(
stage
).
to
have_warnings
end
end
end
end
end
context
'when stage does not have warnings'
do
context
'when stage does not have warnings'
do
before
do
before
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