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
Boxiang Sun
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
...
@@ -51,7 +51,7 @@ module Ci
end
end
def
stages_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
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
)
builds
=
builds_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
)
{
name:
stage
,
builds_attributes:
builds
.
to_a
}
if
builds
.
any?
{
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
Gitlab
module
Ci
module
Ci
module
Stage
module
Stage
class
Seed
class
Seed
s
attr_reader
:name
,
:builds
Seed
=
Struct
.
new
(
:stage
,
:jobs
)
def
initialize
(
name
:,
builds
:)
def
initialize
@name
=
name
@stages
=
[]
@builds
=
builds
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
end
def
pipeline
=
(
pipeline
)
def
pipeline
=
(
pipeline
)
trigger_request
=
pipeline
.
trigger_requests
.
first
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!
(
attributes
.
merge!
(
pipeline:
pipeline
,
pipeline:
pipeline
,
project:
pipeline
.
project
,
project:
pipeline
.
project
,
...
@@ -24,13 +42,15 @@ module Gitlab
...
@@ -24,13 +42,15 @@ module Gitlab
end
end
def
user
=
(
current_user
)
def
user
=
(
current_user
)
@build
s
.
each
do
|
attributes
|
job
s
.
each
do
|
attributes
|
attributes
.
merge!
(
user:
current_user
)
attributes
.
merge!
(
user:
current_user
)
end
end
end
end
def
to_attributes
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
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'
require
'spec_helper'
describe
Gitlab
::
Ci
::
Stage
::
Seed
do
describe
Gitlab
::
Ci
::
Stage
::
Seeds
do
subject
do
before
do
described_class
.
new
(
name:
'test'
,
builds:
builds
)
subject
.
append_stage
(
'test'
,
[{
name:
'rspec'
},
{
name:
'spinach'
}])
subject
.
append_stage
(
'deploy'
,
[{
name:
'prod'
,
script:
'cap deploy'
}])
end
end
let
(
:builds
)
do
describe
'#stages'
do
[{
name:
'rspec'
},
{
name:
'spinach'
}]
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
end
describe
'#pipeline='
do
describe
'#pipeline='
do
...
@@ -19,11 +29,13 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -19,11 +29,13 @@ describe Gitlab::Ci::Stage::Seed do
subject
.
pipeline
=
pipeline
subject
.
pipeline
=
pipeline
expect
(
subject
.
builds
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
stages
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
builds
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
stages
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
).
to
all
(
include
(
ref:
'feature'
))
expect
(
subject
.
jobs
).
to
all
(
include
(
pipeline:
pipeline
))
expect
(
subject
.
builds
).
to
all
(
include
(
tag:
true
))
expect
(
subject
.
jobs
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
).
to
all
(
include
(
trigger_request:
trigger_request
))
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
end
end
...
@@ -33,15 +45,18 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -33,15 +45,18 @@ describe Gitlab::Ci::Stage::Seed do
it
'assignes relevant pipeline attributes'
do
it
'assignes relevant pipeline attributes'
do
subject
.
user
=
user
subject
.
user
=
user
expect
(
subject
.
build
s
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
job
s
).
to
all
(
include
(
user:
user
))
end
end
end
end
describe
'#to_attributes'
do
describe
'#to_attributes'
do
it
'exposes stage attributes with nested jobs'
do
it
'exposes stage attributes with nested jobs'
do
expect
(
subject
.
to_attributes
).
to
be_a
Hash
attributes
=
[{
name:
'test'
,
builds_attributes:
expect
(
subject
.
to_attributes
).
to
include
(
name:
'test'
)
[{
name:
'rspec'
},
{
name:
'spinach'
}]
},
expect
(
subject
.
to_attributes
).
to
include
(
builds_attributes:
builds
)
{
name:
'deploy'
,
builds_attributes:
[{
name:
'prod'
,
script:
'cap deploy'
}]
}]
expect
(
subject
.
to_attributes
).
to
eq
attributes
end
end
end
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