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
b24b45be
Commit
b24b45be
authored
Mar 19, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Instantiate pipeline stages and builds before saving
parent
6cfea81e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
37 deletions
+41
-37
lib/gitlab/ci/stage/seed.rb
lib/gitlab/ci/stage/seed.rb
+17
-13
spec/lib/gitlab/ci/stage/seed_spec.rb
spec/lib/gitlab/ci/stage/seed_spec.rb
+12
-12
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+12
-12
No files found.
lib/gitlab/ci/stage/seed.rb
View file @
b24b45be
...
@@ -7,28 +7,28 @@ module Gitlab
...
@@ -7,28 +7,28 @@ module Gitlab
attr_reader
:pipeline
attr_reader
:pipeline
delegate
:project
,
to: :pipeline
delegate
:project
,
to: :pipeline
delegate
:size
,
to: :@
job
s
delegate
:size
,
to: :@
build
s
def
initialize
(
pipeline
,
stage
,
job
s
)
def
initialize
(
pipeline
,
stage
,
build
s
)
@pipeline
=
pipeline
@pipeline
=
pipeline
@stage
=
{
name:
stage
}
@stage
=
stage
# stage name
@
jobs
=
jobs
.
to_a
.
dup
@
builds
=
builds
.
to_a
.
dup
# builds array of hashes
end
end
def
user
=
(
current_user
)
def
user
=
(
current_user
)
@
job
s
.
map!
do
|
attributes
|
@
build
s
.
map!
do
|
attributes
|
attributes
.
merge
(
user:
current_user
)
attributes
.
merge
(
user:
current_user
)
end
end
end
end
def
stage
def
stage
_attributes
@stage
.
merge
(
project:
project
)
{
name:
@stage
,
project:
project
}
end
end
def
builds
def
builds
_attributes
trigger
=
pipeline
.
trigger_requests
.
first
trigger
=
pipeline
.
trigger_requests
.
first
@
job
s
.
map
do
|
attributes
|
@
build
s
.
map
do
|
attributes
|
attributes
.
merge
(
project:
project
,
attributes
.
merge
(
project:
project
,
ref:
pipeline
.
ref
,
ref:
pipeline
.
ref
,
tag:
pipeline
.
tag
,
tag:
pipeline
.
tag
,
...
@@ -38,12 +38,16 @@ module Gitlab
...
@@ -38,12 +38,16 @@ module Gitlab
end
end
def
create!
def
create!
pipeline
.
stages
.
create!
(
stage
).
tap
do
|
stage
|
pipeline
.
stages
.
build
(
stage_attributes
).
tap
do
|
stage
|
builds_attributes
=
builds
.
map
do
|
attributes
|
builds_attributes
.
each
do
|
build_attributes
|
attributes
.
merge
(
stage_id:
stage
.
id
)
stage
.
builds
.
build
(
build_attributes
).
tap
do
|
build
|
build
.
pipeline
=
pipeline
end
end
end
stage
.
save!
pipeline
.
builds
.
create!
(
builds_attributes
)
.
each
do
|
build
|
stage
.
builds
.
each
do
|
build
|
yield
build
if
block_given?
yield
build
if
block_given?
end
end
end
end
...
...
spec/lib/gitlab/ci/stage/seed_spec.rb
View file @
b24b45be
...
@@ -17,20 +17,20 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -17,20 +17,20 @@ describe Gitlab::Ci::Stage::Seed do
end
end
end
end
describe
'#stage'
do
describe
'#stage
_attributes
'
do
it
'returns hash attributes of a stage'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
stage
).
to
be_a
Hash
expect
(
subject
.
stage
_attributes
).
to
be_a
Hash
expect
(
subject
.
stage
).
to
include
(
:name
,
:project
)
expect
(
subject
.
stage
_attributes
).
to
include
(
:name
,
:project
)
end
end
end
end
describe
'#builds'
do
describe
'#builds
_attributes
'
do
it
'returns hash attributes of all builds'
do
it
'returns hash attributes of all builds'
do
expect
(
subject
.
builds
.
size
).
to
eq
2
expect
(
subject
.
builds
_attributes
.
size
).
to
eq
2
expect
(
subject
.
builds
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
)
expect
(
subject
.
builds
_attributes
)
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
end
end
...
@@ -40,7 +40,7 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -40,7 +40,7 @@ describe Gitlab::Ci::Stage::Seed do
end
end
it
'returns protected builds'
do
it
'returns protected builds'
do
expect
(
subject
.
builds
).
to
all
(
include
(
protected:
true
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
protected:
true
))
end
end
end
end
...
@@ -50,7 +50,7 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -50,7 +50,7 @@ describe Gitlab::Ci::Stage::Seed do
end
end
it
'returns unprotected builds'
do
it
'returns unprotected builds'
do
expect
(
subject
.
builds
).
to
all
(
include
(
protected:
false
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
protected:
false
))
end
end
end
end
end
end
...
@@ -61,7 +61,7 @@ describe Gitlab::Ci::Stage::Seed do
...
@@ -61,7 +61,7 @@ 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
.
builds
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
user:
user
))
end
end
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
b24b45be
...
@@ -119,11 +119,11 @@ module Gitlab
...
@@ -119,11 +119,11 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
stage
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
second
.
stage
_attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
second
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
end
end
end
end
...
@@ -141,8 +141,8 @@ module Gitlab
...
@@ -141,8 +141,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
...
@@ -160,8 +160,8 @@ module Gitlab
...
@@ -160,8 +160,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
end
end
...
@@ -183,8 +183,8 @@ module Gitlab
...
@@ -183,8 +183,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
second
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
end
end
end
end
...
@@ -209,7 +209,7 @@ module Gitlab
...
@@ -209,7 +209,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
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