BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c72e21fd
Commit
c72e21fd
authored
May 31, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Return stage seeds object from YAML processor
parent
c881425b
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
26 deletions
+34
-26
pipeline.rb
app/models/ci/pipeline.rb
+5
-3
gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+6
-6
seeds.rb
lib/gitlab/ci/stage/seeds.rb
+5
-1
gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+14
-16
seeds_spec.rb
spec/lib/gitlab/ci/stage/seeds_spec.rb
+4
-0
No files found.
app/models/ci/pipeline.rb
View file @
c72e21fd
...
@@ -295,14 +295,16 @@ module Ci
...
@@ -295,14 +295,16 @@ module Ci
sort_by
{
|
build
|
build
[
:stage_idx
]
}
sort_by
{
|
build
|
build
[
:stage_idx
]
}
end
end
def
config_stages_attribute
s
def
stage_seed
s
return
[]
unless
config_processor
return
[]
unless
config_processor
config_processor
.
stages_for_ref
(
ref
,
tag?
,
trigger_requests
.
first
)
config_processor
.
stage_seeds
(
ref:
ref
,
tag:
tag?
,
trigger:
trigger_requests
.
first
)
end
end
def
has_stages?
def
has_stages?
config_stages_attributes
.
any
?
stage_seeds
.
has_stages
?
end
end
def
has_warnings?
def
has_warnings?
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
c72e21fd
...
@@ -50,14 +50,14 @@ module Ci
...
@@ -50,14 +50,14 @@ module Ci
end
end
end
end
def
stages_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
def
stage_seeds
(
ref
:,
tag:
false
,
trigger:
nil
)
stages
=
@stages
.
uniq
.
map
do
|
stage
|
Gitlab
::
Ci
::
Stage
::
Seeds
.
new
.
tap
do
|
seeds
|
builds
=
builds_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
)
@stages
.
uniq
.
each
do
|
stage
|
builds
=
builds_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger
)
{
name:
stage
,
builds_attributes:
builds
.
to_a
}
if
builds
.
any?
seeds
.
append_stage
(
stage
,
builds
)
if
builds
.
any?
end
end
end
stages
.
compact
.
sort_by
{
|
stage
|
@stages
.
index
(
stage
[
:name
])
}
end
end
def
build_attributes
(
name
)
def
build_attributes
(
name
)
...
...
lib/gitlab/ci/stage/seeds.rb
View file @
c72e21fd
...
@@ -8,6 +8,10 @@ module Gitlab
...
@@ -8,6 +8,10 @@ module Gitlab
@stages
=
[]
@stages
=
[]
end
end
def
has_stages?
@stages
.
any?
end
def
stages
def
stages
@stages
.
map
(
&
:stage
)
@stages
.
map
(
&
:stage
)
end
end
...
@@ -48,7 +52,7 @@ module Gitlab
...
@@ -48,7 +52,7 @@ module Gitlab
end
end
def
to_attributes
def
to_attributes
@stages
.
map
.
with_index
do
|
seed
|
@stages
.
map
do
|
seed
|
seed
.
stage
.
merge
(
builds_attributes:
seed
.
jobs
)
seed
.
stage
.
merge
(
builds_attributes:
seed
.
jobs
)
end
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
c72e21fd
...
@@ -83,7 +83,7 @@ module Ci
...
@@ -83,7 +83,7 @@ module Ci
end
end
end
end
describe
'#stage
s_for_ref
'
do
describe
'#stage
_seeds
'
do
context
'when no refs policy is specified'
do
context
'when no refs policy is specified'
do
let
(
:config
)
do
let
(
:config
)
do
YAML
.
dump
(
production:
{
stage:
'deploy'
,
script:
'cap prod'
},
YAML
.
dump
(
production:
{
stage:
'deploy'
,
script:
'cap prod'
},
...
@@ -91,15 +91,15 @@ module Ci
...
@@ -91,15 +91,15 @@ module Ci
spinach:
{
stage:
'test'
,
script:
'spinach'
})
spinach:
{
stage:
'test'
,
script:
'spinach'
})
end
end
it
'returns
model attributes for stages with nested jobs
'
do
it
'returns
correctly fabricated stage seeds object
'
do
attributes
=
subject
.
stages_for_ref
(
'master'
)
seeds
=
subject
.
stage_seeds
(
ref:
'master'
)
expect
(
attribut
es
.
size
).
to
eq
2
expect
(
seeds
.
stag
es
.
size
).
to
eq
2
expect
(
attribut
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
seeds
.
stag
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
attribut
es
.
dig
(
1
,
:name
)).
to
eq
'deploy'
expect
(
seeds
.
stag
es
.
dig
(
1
,
:name
)).
to
eq
'deploy'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
jobs
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
jobs
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
attributes
.
dig
(
1
,
:builds_attributes
,
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
jobs
.
dig
(
2
,
:name
)).
to
eq
'production'
end
end
end
end
...
@@ -109,14 +109,12 @@ module Ci
...
@@ -109,14 +109,12 @@ module Ci
spinach:
{
stage:
'test'
,
script:
'spinach'
,
only:
[
'tags'
]
})
spinach:
{
stage:
'test'
,
script:
'spinach'
,
only:
[
'tags'
]
})
end
end
it
'returns stage attributes except of jobs assigned to master'
do
it
'returns stage seeds only assigned to master to master'
do
# true flag argument means matching jobs for tags
seeds
=
subject
.
stage_seeds
(
ref:
'feature'
,
tag:
true
)
#
attributes
=
subject
.
stages_for_ref
(
'feature'
,
true
)
expect
(
attribut
es
.
size
).
to
eq
1
expect
(
seeds
.
stag
es
.
size
).
to
eq
1
expect
(
attribut
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
seeds
.
stag
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
jobs
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
end
end
...
...
spec/lib/gitlab/ci/stage/seeds_spec.rb
View file @
c72e21fd
...
@@ -6,6 +6,10 @@ describe Gitlab::Ci::Stage::Seeds do
...
@@ -6,6 +6,10 @@ describe Gitlab::Ci::Stage::Seeds do
subject
.
append_stage
(
'deploy'
,
[{
name:
'prod'
,
script:
'cap deploy'
}])
subject
.
append_stage
(
'deploy'
,
[{
name:
'prod'
,
script:
'cap deploy'
}])
end
end
describe
'#has_stages?'
do
it
{
is_expected
.
to
have_stages
}
end
describe
'#stages'
do
describe
'#stages'
do
it
'returns hashes of all stages'
do
it
'returns hashes of all stages'
do
expect
(
subject
.
stages
.
size
).
to
eq
2
expect
(
subject
.
stages
.
size
).
to
eq
2
...
...
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