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
c881425b
Commit
c881425b
authored
May 31, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refine pipeline stages seeds class
parent
805715cc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
1 deletion
+121
-1
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+1
-1
lib/gitlab/ci/stage/seeds.rb
lib/gitlab/ci/stage/seeds.rb
+58
-0
spec/lib/gitlab/ci/stage/seeds_spec.rb
spec/lib/gitlab/ci/stage/seeds_spec.rb
+62
-0
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
c881425b
...
...
@@ -51,7 +51,7 @@ module Ci
end
def
stages_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
stages
=
@stages
.
map
do
|
stage
|
stages
=
@stages
.
uniq
.
map
do
|
stage
|
builds
=
builds_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
)
{
name:
stage
,
builds_attributes:
builds
.
to_a
}
if
builds
.
any?
...
...
lib/gitlab/ci/stage/seed.rb
→
lib/gitlab/ci/stage/seed
s
.rb
View file @
c881425b
module
Gitlab
module
Ci
module
Stage
class
Seed
attr_reader
:name
,
:builds
class
Seed
s
Seed
=
Struct
.
new
(
:stage
,
:jobs
)
def
initialize
(
name
:,
builds
:)
@name
=
name
@builds
=
builds
def
initialize
@stages
=
[]
end
def
stages
@stages
.
map
(
&
:stage
)
end
def
jobs
@stages
.
map
(
&
:jobs
).
flatten
end
def
append_stage
(
stage
,
jobs
)
@stages
<<
Seed
.
new
({
name:
stage
},
jobs
)
end
def
pipeline
=
(
pipeline
)
trigger_request
=
pipeline
.
trigger_requests
.
first
@builds
.
each
do
|
attributes
|
stages
.
each
do
|
attributes
|
attributes
.
merge!
(
pipeline:
pipeline
,
project:
pipeline
.
project
,
)
end
jobs
.
each
do
|
attributes
|
attributes
.
merge!
(
pipeline:
pipeline
,
project:
pipeline
.
project
,
...
...
@@ -24,13 +42,15 @@ module Gitlab
end
def
user
=
(
current_user
)
@build
s
.
each
do
|
attributes
|
job
s
.
each
do
|
attributes
|
attributes
.
merge!
(
user:
current_user
)
end
end
def
to_attributes
{
name:
@name
,
builds_attributes:
@builds
}
@stages
.
map
.
with_index
do
|
seed
|
seed
.
stage
.
merge
(
builds_attributes:
seed
.
jobs
)
end
end
end
end
...
...
spec/lib/gitlab/ci/stage/seed_spec.rb
→
spec/lib/gitlab/ci/stage/seed
s
_spec.rb
View file @
c881425b
require
'spec_helper'
describe
Gitlab
::
Ci
::
Stage
::
Seed
do
subject
do
described_class
.
new
(
name:
'test'
,
builds:
builds
)
describe
Gitlab
::
Ci
::
Stage
::
Seeds
do
before
do
subject
.
append_stage
(
'test'
,
[{
name:
'rspec'
},
{
name:
'spinach'
}])
subject
.
append_stage
(
'deploy'
,
[{
name:
'prod'
,
script:
'cap deploy'
}])
end
let
(
:builds
)
do
[{
name:
'rspec'
},
{
name:
'spinach'
}]
describe
'#stages'
do
it
'returns hashes of all stages'
do
expect
(
subject
.
stages
.
size
).
to
eq
2
expect
(
subject
.
stages
).
to
all
(
be_a
Hash
)
end
end
describe
'#jobs'
do
it
'returns all jobs in all stages'
do
expect
(
subject
.
jobs
.
size
).
to
eq
3
end
end
describe
'#pipeline='
do
...
...
@@ -19,11 +29,13 @@ describe Gitlab::Ci::Stage::Seed do
subject
.
pipeline
=
pipeline
expect
(
subject
.
builds
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
builds
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
).
to
all
(
include
(
ref:
'feature'
))
expect
(
subject
.
builds
).
to
all
(
include
(
tag:
true
))
expect
(
subject
.
builds
).
to
all
(
include
(
trigger_request:
trigger_request
))
expect
(
subject
.
stages
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
stages
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
jobs
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
jobs
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
jobs
).
to
all
(
include
(
ref:
'feature'
))
expect
(
subject
.
jobs
).
to
all
(
include
(
tag:
true
))
expect
(
subject
.
jobs
).
to
all
(
include
(
trigger_request:
trigger_request
))
end
end
...
...
@@ -33,15 +45,18 @@ describe Gitlab::Ci::Stage::Seed do
it
'assignes relevant pipeline attributes'
do
subject
.
user
=
user
expect
(
subject
.
build
s
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
job
s
).
to
all
(
include
(
user:
user
))
end
end
describe
'#to_attributes'
do
it
'exposes stage attributes with nested jobs'
do
expect
(
subject
.
to_attributes
).
to
be_a
Hash
expect
(
subject
.
to_attributes
).
to
include
(
name:
'test'
)
expect
(
subject
.
to_attributes
).
to
include
(
builds_attributes:
builds
)
attributes
=
[{
name:
'test'
,
builds_attributes:
[{
name:
'rspec'
},
{
name:
'spinach'
}]
},
{
name:
'deploy'
,
builds_attributes:
[{
name:
'prod'
,
script:
'cap deploy'
}]
}]
expect
(
subject
.
to_attributes
).
to
eq
attributes
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