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
Léo-Paul Géneau
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
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
26 deletions
+34
-26
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+5
-3
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+6
-6
lib/gitlab/ci/stage/seeds.rb
lib/gitlab/ci/stage/seeds.rb
+5
-1
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+14
-16
spec/lib/gitlab/ci/stage/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
sort_by
{
|
build
|
build
[
:stage_idx
]
}
end
def
config_stages_attribute
s
def
stage_seed
s
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
def
has_stages?
config_stages_attributes
.
any
?
stage_seeds
.
has_stages
?
end
def
has_warnings?
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
c72e21fd
...
...
@@ -50,14 +50,14 @@ module Ci
end
end
def
stages_for_ref
(
ref
,
tag
=
false
,
trigger_request
=
nil
)
stages
=
@stages
.
uniq
.
map
do
|
stage
|
builds
=
builds_for_stage_and_ref
(
stage
,
ref
,
tag
,
trigger_request
)
def
stage_seeds
(
ref
:,
tag:
false
,
trigger:
nil
)
Gitlab
::
Ci
::
Stage
::
Seeds
.
new
.
tap
do
|
seeds
|
@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
stages
.
compact
.
sort_by
{
|
stage
|
@stages
.
index
(
stage
[
:name
])
}
end
def
build_attributes
(
name
)
...
...
lib/gitlab/ci/stage/seeds.rb
View file @
c72e21fd
...
...
@@ -8,6 +8,10 @@ module Gitlab
@stages
=
[]
end
def
has_stages?
@stages
.
any?
end
def
stages
@stages
.
map
(
&
:stage
)
end
...
...
@@ -48,7 +52,7 @@ module Gitlab
end
def
to_attributes
@stages
.
map
.
with_index
do
|
seed
|
@stages
.
map
do
|
seed
|
seed
.
stage
.
merge
(
builds_attributes:
seed
.
jobs
)
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
c72e21fd
...
...
@@ -83,7 +83,7 @@ module Ci
end
end
describe
'#stage
s_for_ref
'
do
describe
'#stage
_seeds
'
do
context
'when no refs policy is specified'
do
let
(
:config
)
do
YAML
.
dump
(
production:
{
stage:
'deploy'
,
script:
'cap prod'
},
...
...
@@ -91,15 +91,15 @@ module Ci
spinach:
{
stage:
'test'
,
script:
'spinach'
})
end
it
'returns
model attributes for stages with nested jobs
'
do
attributes
=
subject
.
stages_for_ref
(
'master'
)
it
'returns
correctly fabricated stage seeds object
'
do
seeds
=
subject
.
stage_seeds
(
ref:
'master'
)
expect
(
attribut
es
.
size
).
to
eq
2
expect
(
attribut
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
attribut
es
.
dig
(
1
,
:name
)).
to
eq
'deploy'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
0
,
:name
)).
to
eq
'rspec'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
1
,
:name
)).
to
eq
'spinach'
expect
(
attributes
.
dig
(
1
,
:builds_attributes
,
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
stag
es
.
size
).
to
eq
2
expect
(
seeds
.
stag
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
seeds
.
stag
es
.
dig
(
1
,
:name
)).
to
eq
'deploy'
expect
(
seeds
.
jobs
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
jobs
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
jobs
.
dig
(
2
,
:name
)).
to
eq
'production'
end
end
...
...
@@ -109,14 +109,12 @@ module Ci
spinach:
{
stage:
'test'
,
script:
'spinach'
,
only:
[
'tags'
]
})
end
it
'returns stage attributes except of jobs assigned to master'
do
# true flag argument means matching jobs for tags
#
attributes
=
subject
.
stages_for_ref
(
'feature'
,
true
)
it
'returns stage seeds only assigned to master to master'
do
seeds
=
subject
.
stage_seeds
(
ref:
'feature'
,
tag:
true
)
expect
(
attribut
es
.
size
).
to
eq
1
expect
(
attribut
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
attributes
.
dig
(
0
,
:builds_attributes
,
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
stag
es
.
size
).
to
eq
1
expect
(
seeds
.
stag
es
.
dig
(
0
,
:name
)).
to
eq
'test'
expect
(
seeds
.
jobs
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
end
...
...
spec/lib/gitlab/ci/stage/seeds_spec.rb
View file @
c72e21fd
...
...
@@ -6,6 +6,10 @@ describe Gitlab::Ci::Stage::Seeds do
subject
.
append_stage
(
'deploy'
,
[{
name:
'prod'
,
script:
'cap deploy'
}])
end
describe
'#has_stages?'
do
it
{
is_expected
.
to
have_stages
}
end
describe
'#stages'
do
it
'returns hashes of all stages'
do
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