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
8cca6c83
Commit
8cca6c83
authored
May 23, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY creating groups of common builds in a stage
parent
f89f232d
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
10 deletions
+61
-10
app/models/ci/group.rb
app/models/ci/group.rb
+8
-0
app/models/ci/legacy_stage.rb
app/models/ci/legacy_stage.rb
+1
-5
app/models/ci/stage.rb
app/models/ci/stage.rb
+1
-5
spec/models/ci/group_spec.rb
spec/models/ci/group_spec.rb
+51
-0
No files found.
app/models/ci/group.rb
View file @
8cca6c83
...
...
@@ -31,6 +31,14 @@ module Ci
end
end
def
self
.
fabricate
(
stage
)
stage
.
statuses
.
ordered
.
latest
.
sort_by
(
&
:sortable_name
).
group_by
(
&
:group_name
)
.
map
do
|
group_name
,
grouped_statuses
|
self
.
new
(
stage
,
name:
group_name
,
jobs:
grouped_statuses
)
end
end
private
def
commit_statuses
...
...
app/models/ci/legacy_stage.rb
View file @
8cca6c83
...
...
@@ -16,11 +16,7 @@ module Ci
end
def
groups
@groups
||=
statuses
.
ordered
.
latest
.
sort_by
(
&
:sortable_name
).
group_by
(
&
:group_name
)
.
map
do
|
group_name
,
grouped_statuses
|
Ci
::
Group
.
new
(
self
,
name:
group_name
,
jobs:
grouped_statuses
)
end
@groups
||=
Ci
::
Group
.
fabricate
(
self
)
end
def
to_param
...
...
app/models/ci/stage.rb
View file @
8cca6c83
...
...
@@ -81,11 +81,7 @@ module Ci
end
def
groups
@groups
||=
statuses
.
ordered
.
latest
.
sort_by
(
&
:sortable_name
).
group_by
(
&
:group_name
)
.
map
do
|
group_name
,
grouped_statuses
|
Ci
::
Group
.
new
(
self
,
name:
group_name
,
jobs:
grouped_statuses
)
end
@groups
||=
Ci
::
Group
.
fabricate
(
self
)
end
def
has_warnings?
...
...
spec/models/ci/group_spec.rb
View file @
8cca6c83
...
...
@@ -41,4 +41,55 @@ describe Ci::Group do
end
end
end
describe
'.fabricate'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
let
(
:stage
)
{
create
(
:ci_stage_entity
,
pipeline:
pipeline
)
}
before
do
create_build
(
:ci_build
,
name:
'rspec 0 2'
)
create_build
(
:ci_build
,
name:
'rspec 0 1'
)
create_build
(
:ci_build
,
name:
'spinach 0 1'
)
create_build
(
:commit_status
,
name:
'aaaaa'
)
end
it
'returns an array of three groups'
do
expect
(
stage
.
groups
).
to
be_a
Array
expect
(
stage
.
groups
).
to
all
(
be_a
Ci
::
Group
)
expect
(
stage
.
groups
.
size
).
to
eq
3
end
it
'returns groups with correctly ordered statuses'
do
expect
(
stage
.
groups
.
first
.
jobs
.
map
(
&
:name
))
.
to
eq
[
'aaaaa'
]
expect
(
stage
.
groups
.
second
.
jobs
.
map
(
&
:name
))
.
to
eq
[
'rspec 0 1'
,
'rspec 0 2'
]
expect
(
stage
.
groups
.
third
.
jobs
.
map
(
&
:name
))
.
to
eq
[
'spinach 0 1'
]
end
it
'returns groups with correct names'
do
expect
(
stage
.
groups
.
map
(
&
:name
))
.
to
eq
%w[aaaaa rspec spinach]
end
context
'when a name is nil on legacy pipelines'
do
before
do
pipeline
.
builds
.
first
.
update_attribute
(
:name
,
nil
)
end
it
'returns an array of three groups'
do
expect
(
stage
.
groups
.
map
(
&
:name
))
.
to
eq
[
''
,
'aaaaa'
,
'rspec'
,
'spinach'
]
end
end
def
create_build
(
type
,
status:
'success'
,
**
opts
)
create
(
type
,
pipeline:
pipeline
,
stage:
stage
.
name
,
status:
status
,
stage_id:
stage
.
id
,
**
opts
)
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