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
Hide 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
attr_reader
: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
@stage
=
{
name:
stage
}
@
jobs
=
jobs
.
to_a
.
dup
@stage
=
stage
# stage name
@
builds
=
builds
.
to_a
.
dup
# builds array of hashes
end
def
user
=
(
current_user
)
@
job
s
.
map!
do
|
attributes
|
@
build
s
.
map!
do
|
attributes
|
attributes
.
merge
(
user:
current_user
)
end
end
def
stage
@stage
.
merge
(
project:
project
)
def
stage
_attributes
{
name:
@stage
,
project:
project
}
end
def
builds
def
builds
_attributes
trigger
=
pipeline
.
trigger_requests
.
first
@
job
s
.
map
do
|
attributes
|
@
build
s
.
map
do
|
attributes
|
attributes
.
merge
(
project:
project
,
ref:
pipeline
.
ref
,
tag:
pipeline
.
tag
,
...
...
@@ -38,12 +38,16 @@ module Gitlab
end
def
create!
pipeline
.
stages
.
create!
(
stage
).
tap
do
|
stage
|
builds_attributes
=
builds
.
map
do
|
attributes
|
attributes
.
merge
(
stage_id:
stage
.
id
)
pipeline
.
stages
.
build
(
stage_attributes
).
tap
do
|
stage
|
builds_attributes
.
each
do
|
build_attributes
|
stage
.
builds
.
build
(
build_attributes
).
tap
do
|
build
|
build
.
pipeline
=
pipeline
end
end
pipeline
.
builds
.
create!
(
builds_attributes
).
each
do
|
build
|
stage
.
save!
stage
.
builds
.
each
do
|
build
|
yield
build
if
block_given?
end
end
...
...
spec/lib/gitlab/ci/stage/seed_spec.rb
View file @
b24b45be
...
...
@@ -17,20 +17,20 @@ describe Gitlab::Ci::Stage::Seed do
end
end
describe
'#stage'
do
describe
'#stage
_attributes
'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
stage
).
to
be_a
Hash
expect
(
subject
.
stage
).
to
include
(
:name
,
:project
)
expect
(
subject
.
stage
_attributes
).
to
be_a
Hash
expect
(
subject
.
stage
_attributes
).
to
include
(
:name
,
:project
)
end
end
describe
'#builds'
do
describe
'#builds
_attributes
'
do
it
'returns hash attributes of all builds'
do
expect
(
subject
.
builds
.
size
).
to
eq
2
expect
(
subject
.
builds
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
)
expect
(
subject
.
builds
_attributes
.
size
).
to
eq
2
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
ref:
'master'
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
tag:
false
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
project:
pipeline
.
project
))
expect
(
subject
.
builds
_attributes
)
.
to
all
(
include
(
trigger_request:
pipeline
.
trigger_requests
.
first
))
end
...
...
@@ -40,7 +40,7 @@ describe Gitlab::Ci::Stage::Seed do
end
it
'returns protected builds'
do
expect
(
subject
.
builds
).
to
all
(
include
(
protected:
true
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
protected:
true
))
end
end
...
...
@@ -50,7 +50,7 @@ describe Gitlab::Ci::Stage::Seed do
end
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
...
...
@@ -61,7 +61,7 @@ describe Gitlab::Ci::Stage::Seed do
it
'assignes relevant pipeline attributes'
do
subject
.
user
=
user
expect
(
subject
.
builds
).
to
all
(
include
(
user:
user
))
expect
(
subject
.
builds
_attributes
).
to
all
(
include
(
user:
user
))
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
b24b45be
...
...
@@ -119,11 +119,11 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
stage
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
stage
_attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'rspec'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
1
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
end
end
...
...
@@ -141,8 +141,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
...
...
@@ -160,8 +160,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
first
.
stage
_attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
...
...
@@ -183,8 +183,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
builds
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
.
dig
(
0
,
:name
)).
to
eq
'production'
expect
(
seeds
.
first
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
expect
(
seeds
.
second
.
builds
_attributes
.
dig
(
0
,
:name
)).
to
eq
'production'
end
end
...
...
@@ -209,7 +209,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
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
...
...
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