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
Jérome Perrin
gitlab-ce
Commits
ab0cd2a8
Commit
ab0cd2a8
authored
Mar 21, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce pipeline build seeds
parent
d16bb447
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
29 deletions
+63
-29
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+17
-0
lib/gitlab/ci/pipeline/seed/build.rb
lib/gitlab/ci/pipeline/seed/build.rb
+28
-0
lib/gitlab/ci/pipeline/seed/stage.rb
lib/gitlab/ci/pipeline/seed/stage.rb
+12
-23
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
+2
-2
spec/lib/gitlab/ci/yaml_processor_spec.rb
spec/lib/gitlab/ci/yaml_processor_spec.rb
+4
-4
No files found.
app/models/ci/pipeline.rb
View file @
ab0cd2a8
...
...
@@ -6,6 +6,7 @@ module Ci
include
AfterCommitQueue
include
Presentable
include
Gitlab
::
OptimisticLocking
include
Gitlab
::
Utils
::
StrongMemoize
belongs_to
:project
,
inverse_of: :pipelines
belongs_to
:user
...
...
@@ -472,6 +473,22 @@ module Ci
end
end
# TODO specs
#
def
protected_ref?
strong_memoize
(
:protected_ref
)
do
project
.
protected_for?
(
ref
)
end
end
# TODO specs
#
def
legacy_trigger
strong_memoize
(
:legacy_trigger
)
do
trigger_requests
.
first
end
end
def
predefined_variables
Gitlab
::
Ci
::
Variables
::
Collection
.
new
.
append
(
key:
'CI_PIPELINE_ID'
,
value:
id
.
to_s
)
...
...
lib/gitlab/ci/pipeline/seed/build.rb
0 → 100644
View file @
ab0cd2a8
module
Gitlab
module
Ci
module
Pipeline
module
Seed
class
Build
<
Seed
::
Base
def
initialize
(
pipeline
,
attributes
)
@pipeline
=
pipeline
@attributes
=
attributes
end
# TODO find a different solution
#
def
user
=
(
current_user
)
@attributes
.
merge!
(
user:
current_user
)
end
def
attributes
@attributes
.
merge
(
project:
@pipeline
.
project
,
ref:
@pipeline
.
ref
,
tag:
@pipeline
.
tag
,
trigger_request:
@pipeline
.
legacy_trigger
,
protected:
@pipeline
.
protected_ref?
)
end
end
end
end
end
end
lib/gitlab/ci/pipeline/seed/stage.rb
View file @
ab0cd2a8
...
...
@@ -3,43 +3,35 @@ module Gitlab
module
Pipeline
module
Seed
class
Stage
<
Seed
::
Base
include
::
Gitlab
::
Utils
::
StrongMemoize
attr_reader
:pipeline
delegate
:project
,
to: :pipeline
delegate
:size
,
to: :@builds
def
initialize
(
pipeline
,
stag
e
,
builds
)
def
initialize
(
pipeline
,
nam
e
,
builds
)
@pipeline
=
pipeline
@stage
=
stage
# stage name
@builds
=
builds
.
to_a
.
dup
# builds array of hashes
@name
=
name
@builds
=
builds
.
map
do
|
attributes
|
Seed
::
Build
.
new
(
pipeline
,
attributes
)
end
end
def
user
=
(
current_user
)
@builds
.
map!
do
|
attributes
|
attributes
.
merge
(
user:
current_user
)
end
@builds
.
each
{
|
seed
|
seed
.
user
=
current_user
}
end
def
stage_
attributes
{
name:
@
stag
e
,
project:
project
}
def
attributes
{
name:
@
nam
e
,
project:
project
}
end
# TODO decouple from Seed::Build
def
builds_attributes
trigger
=
pipeline
.
trigger_requests
.
first
@builds
.
map
do
|
attributes
|
attributes
.
merge
(
project:
project
,
ref:
pipeline
.
ref
,
tag:
pipeline
.
tag
,
trigger_request:
trigger
,
protected:
protected_ref?
)
end
@builds
.
map
(
&
:attributes
)
end
def
create!
pipeline
.
stages
.
build
(
stage_
attributes
).
tap
do
|
stage
|
pipeline
.
stages
.
build
(
attributes
).
tap
do
|
stage
|
builds_attributes
.
each
do
|
build_attributes
|
stage
.
builds
.
build
(
build_attributes
).
tap
do
|
build
|
build
.
pipeline
=
pipeline
...
...
@@ -57,9 +49,6 @@ module Gitlab
private
def
protected_ref?
strong_memoize
(
:protected_ref
)
do
project
.
protected_for?
(
pipeline
.
ref
)
end
end
end
end
...
...
spec/lib/gitlab/ci/pipeline/seed/stage_spec.rb
View file @
ab0cd2a8
...
...
@@ -19,8 +19,8 @@ describe Gitlab::Ci::Pipeline::Seed::Stage do
describe
'#stage_attributes'
do
it
'returns hash attributes of a stage'
do
expect
(
subject
.
stage_
attributes
).
to
be_a
Hash
expect
(
subject
.
stage_
attributes
).
to
include
(
:name
,
:project
)
expect
(
subject
.
attributes
).
to
be_a
Hash
expect
(
subject
.
attributes
).
to
include
(
:name
,
:project
)
end
end
...
...
spec/lib/gitlab/ci/yaml_processor_spec.rb
View file @
ab0cd2a8
...
...
@@ -119,8 +119,8 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
2
expect
(
seeds
.
first
.
stage_
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
stage_
attributes
[
:name
]).
to
eq
'deploy'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
second
.
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'
...
...
@@ -141,7 +141,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage_
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
end
end
...
...
@@ -160,7 +160,7 @@ module Gitlab
seeds
=
subject
.
stage_seeds
(
pipeline
)
expect
(
seeds
.
size
).
to
eq
1
expect
(
seeds
.
first
.
stage_
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
attributes
[
:name
]).
to
eq
'test'
expect
(
seeds
.
first
.
builds_attributes
.
dig
(
0
,
:name
)).
to
eq
'spinach'
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