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
9f844dd0
Commit
9f844dd0
authored
Dec 04, 2017
by
Grzegorz Bizon
Committed by
Kamil Trzciński
Dec 04, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract class responsible for building a pipeline / EE
parent
84eab3c9
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
180 additions
and
99 deletions
+180
-99
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+0
-1
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+12
-44
lib/gitlab/ci/pipeline/chain/build.rb
lib/gitlab/ci/pipeline/chain/build.rb
+58
-0
lib/gitlab/ci/pipeline/chain/sequence.rb
lib/gitlab/ci/pipeline/chain/sequence.rb
+6
-7
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
+51
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+38
-41
spec/services/ci/create_pipeline_service_spec.rb
spec/services/ci/create_pipeline_service_spec.rb
+2
-1
spec/support/stub_gitlab_calls.rb
spec/support/stub_gitlab_calls.rb
+6
-0
spec/workers/post_receive_spec.rb
spec/workers/post_receive_spec.rb
+7
-5
No files found.
app/models/ci/pipeline.rb
View file @
9f844dd0
...
...
@@ -52,7 +52,6 @@ module Ci
validates
:status
,
presence:
{
unless: :importing?
}
validate
:valid_commit_sha
,
unless: :importing?
after_initialize
:set_config_source
,
if: :new_record?
after_create
:keep_around_commits
,
unless: :importing?
enum
source:
{
...
...
app/services/ci/create_pipeline_service.rb
View file @
9f844dd0
...
...
@@ -2,7 +2,8 @@ module Ci
class
CreatePipelineService
<
BaseService
attr_reader
:pipeline
SEQUENCE
=
[
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
Abilities
,
SEQUENCE
=
[
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Build
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
Abilities
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
Repository
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Validate
::
Config
,
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Skip
,
...
...
@@ -11,21 +12,16 @@ module Ci
EE
::
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Limit
::
Activity
].
freeze
def
execute
(
source
,
ignore_skip_ci:
false
,
save_on_errors:
true
,
trigger_request:
nil
,
schedule:
nil
,
mirror_update:
false
,
&
block
)
@pipeline
=
Ci
::
Pipeline
.
new
(
source:
source
,
project:
project
,
ref:
ref
,
sha:
sha
,
before_sha:
before_sha
,
tag:
tag_exists?
,
trigger_requests:
Array
(
trigger_request
),
user:
current_user
,
pipeline_schedule:
schedule
,
protected:
project
.
protected_for?
(
ref
)
)
# VALIDATE mirror_update!
command
=
OpenStruct
.
new
(
ignore_skip_ci:
ignore_skip_ci
,
@pipeline
=
Ci
::
Pipeline
.
new
command
=
OpenStruct
.
new
(
source:
source
,
origin_ref:
params
[
:ref
],
checkout_sha:
params
[
:checkout_sha
],
after_sha:
params
[
:after
],
before_sha:
params
[
:before
],
trigger_request:
trigger_request
,
schedule:
schedule
,
ignore_skip_ci:
ignore_skip_ci
,
save_incompleted:
save_on_errors
,
allow_mirror_update:
mirror_update
,
seeds_block:
block
,
...
...
@@ -49,14 +45,6 @@ module Ci
private
def
commit
@commit
||=
project
.
commit
(
origin_sha
||
origin_ref
)
end
def
sha
commit
.
try
(
:id
)
end
def
update_merge_requests_head_pipeline
return
unless
pipeline
.
latest?
...
...
@@ -80,26 +68,6 @@ module Ci
.
created_or_pending
end
def
before_sha
params
[
:checkout_sha
]
||
params
[
:before
]
||
Gitlab
::
Git
::
BLANK_SHA
end
def
origin_sha
params
[
:checkout_sha
]
||
params
[
:after
]
end
def
origin_ref
params
[
:ref
]
end
def
tag_exists?
project
.
repository
.
tag_exists?
(
ref
)
end
def
ref
@ref
||=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
end
def
pipeline_created_counter
@pipeline_created_counter
||=
Gitlab
::
Metrics
.
counter
(
:pipelines_created_total
,
"Counter of pipelines created"
)
...
...
lib/gitlab/ci/pipeline/chain/build.rb
0 → 100644
View file @
9f844dd0
module
Gitlab
module
Ci
module
Pipeline
module
Chain
class
Build
<
Chain
::
Base
include
Chain
::
Helpers
def
perform!
@pipeline
.
assign_attributes
(
source:
@command
.
source
,
project:
@project
,
ref:
ref
,
sha:
sha
,
before_sha:
before_sha
,
tag:
tag_exists?
,
trigger_requests:
Array
(
@command
.
trigger_request
),
user:
@current_user
,
pipeline_schedule:
@command
.
schedule
,
protected:
protected_ref?
)
@pipeline
.
set_config_source
end
def
break?
false
end
private
def
ref
@ref
||=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
end
def
sha
@project
.
commit
(
origin_sha
||
origin_ref
).
try
(
:id
)
end
def
origin_ref
@command
.
origin_ref
end
def
origin_sha
@command
.
checkout_sha
||
@command
.
after_sha
end
def
before_sha
@command
.
checkout_sha
||
@command
.
before_sha
||
Gitlab
::
Git
::
BLANK_SHA
end
def
protected_ref?
@project
.
protected_for?
(
ref
)
end
end
end
end
end
end
lib/gitlab/ci/pipeline/chain/sequence.rb
View file @
9f844dd0
...
...
@@ -5,20 +5,19 @@ module Gitlab
class
Sequence
def
initialize
(
pipeline
,
command
,
sequence
)
@pipeline
=
pipeline
@command
=
command
@sequence
=
sequence
@completed
=
[]
@sequence
=
sequence
.
map
do
|
chain
|
chain
.
new
(
pipeline
,
command
)
end
end
def
build!
@sequence
.
each
do
|
step
|
step
.
perform!
@sequence
.
each
do
|
chain
|
step
=
chain
.
new
(
@pipeline
,
@command
)
step
.
perform!
break
if
step
.
break?
@completed
<<
step
@completed
.
push
(
step
)
end
@pipeline
.
tap
do
...
...
spec/lib/gitlab/ci/pipeline/chain/build_spec.rb
0 → 100644
View file @
9f844dd0
require
'spec_helper'
describe
Gitlab
::
Ci
::
Pipeline
::
Chain
::
Build
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:user
)
{
create
(
:user
)
}
let
(
:pipeline
)
{
Ci
::
Pipeline
.
new
}
let
(
:command
)
do
double
(
'command'
,
source: :push
,
origin_ref:
'master'
,
checkout_sha:
project
.
commit
.
id
,
after_sha:
nil
,
before_sha:
nil
,
trigger_request:
nil
,
schedule:
nil
,
project:
project
,
current_user:
user
)
end
let
(
:step
)
{
described_class
.
new
(
pipeline
,
command
)
}
before
do
stub_repository_ci_yaml_file
(
sha:
anything
)
step
.
perform!
end
it
'never breaks the chain'
do
expect
(
step
.
break?
).
to
be
false
end
it
'fills pipeline object with data'
do
expect
(
pipeline
.
sha
).
not_to
be_empty
expect
(
pipeline
.
sha
).
to
eq
project
.
commit
.
id
expect
(
pipeline
.
ref
).
to
eq
'master'
expect
(
pipeline
.
user
).
to
eq
user
expect
(
pipeline
.
project
).
to
eq
project
end
it
'sets a valid config source'
do
expect
(
pipeline
.
repository_source?
).
to
be
true
end
it
'returns a valid pipeline'
do
expect
(
pipeline
).
to
be_valid
end
it
'does not persist a pipeline'
do
expect
(
pipeline
).
not_to
be_persisted
end
end
spec/models/ci/pipeline_spec.rb
View file @
9f844dd0
...
...
@@ -872,21 +872,17 @@ describe Ci::Pipeline, :mailer do
end
describe
'#set_config_source'
do
context
'on object initialisation'
do
context
'when pipelines does not contain needed data'
do
let
(
:pipeline
)
do
Ci
::
Pipeline
.
new
end
it
'defines source to be unknown'
do
pipeline
.
set_config_source
expect
(
pipeline
).
to
be_unknown_source
end
end
context
'when pipeline contains all needed data'
do
let
(
:pipeline
)
do
Ci
::
Pipeline
.
new
(
project:
project
,
create
(
:ci_pipeline
,
project:
project
,
sha:
'1234'
,
ref:
'master'
,
source: :push
)
...
...
@@ -899,6 +895,8 @@ describe Ci::Pipeline, :mailer do
end
it
'defines source to be from repository'
do
pipeline
.
set_config_source
expect
(
pipeline
).
to
be_repository_source
end
...
...
@@ -924,7 +922,7 @@ describe Ci::Pipeline, :mailer do
end
it
'defines source to be auto devops'
do
subject
pipeline
.
set_config_source
expect
(
pipeline
).
to
be_auto_devops_source
end
...
...
@@ -932,7 +930,6 @@ describe Ci::Pipeline, :mailer do
end
end
end
end
describe
'#ci_yaml_file'
do
let
(
:implied_yml
)
{
Gitlab
::
Template
::
GitlabCiYmlTemplate
.
find
(
'Auto-DevOps'
).
content
}
...
...
spec/services/ci/create_pipeline_service_spec.rb
View file @
9f844dd0
...
...
@@ -8,7 +8,7 @@ describe Ci::CreatePipelineService do
let
(
:ref_name
)
{
'refs/heads/master'
}
before
do
stub_
ci_pipeline_to_return_yaml_file
stub_
repository_ci_yaml_file
(
sha:
anything
)
end
describe
'#execute'
do
...
...
@@ -44,6 +44,7 @@ describe Ci::CreatePipelineService do
expect
(
pipeline
).
to
eq
(
project
.
pipelines
.
last
)
expect
(
pipeline
).
to
have_attributes
(
user:
user
)
expect
(
pipeline
).
to
have_attributes
(
status:
'pending'
)
expect
(
pipeline
.
repository_source?
).
to
be
true
expect
(
pipeline
.
builds
.
first
).
to
be_kind_of
(
Ci
::
Build
)
end
...
...
spec/support/stub_gitlab_calls.rb
View file @
9f844dd0
...
...
@@ -21,6 +21,12 @@ module StubGitlabCalls
allow_any_instance_of
(
Ci
::
Pipeline
).
to
receive
(
:ci_yaml_file
)
{
ci_yaml
}
end
def
stub_repository_ci_yaml_file
(
sha
:,
path:
'.gitlab-ci.yml'
)
allow_any_instance_of
(
Repository
)
.
to
receive
(
:gitlab_ci_yml_for
).
with
(
sha
,
path
)
.
and_return
(
gitlab_ci_yaml
)
end
def
stub_ci_builds_disabled
allow_any_instance_of
(
Project
).
to
receive
(
:builds_enabled?
).
and_return
(
false
)
end
...
...
spec/workers/post_receive_spec.rb
View file @
9f844dd0
...
...
@@ -66,19 +66,21 @@ describe PostReceive do
end
context
"gitlab-ci.yml"
do
let
(
:changes
)
{
"123456 789012 refs/heads/feature
\n
654321 210987 refs/tags/tag"
}
subject
{
described_class
.
new
.
perform
(
gl_repository
,
key_id
,
base64_changes
)
}
context
"creates a Ci::Pipeline for every change"
do
before
do
stub_ci_pipeline_to_return_yaml_file
# TODO, don't stub private methods
#
allow_any_instance_of
(
Ci
::
CreatePipelineService
)
.
to
receive
(
:commit
).
and_return
(
OpenStruct
.
new
(
id:
'123456'
))
allow_any_instance_of
(
Project
)
.
to
receive
(
:commit
)
.
and_return
(
project
.
commit
)
allow_any_instance_of
(
Repository
)
.
to
receive
(
:branch_exists?
).
and_return
(
true
)
.
to
receive
(
:branch_exists?
)
.
and_return
(
true
)
end
it
{
expect
{
subject
}.
to
change
{
Ci
::
Pipeline
.
count
}.
by
(
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