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
Boxiang Sun
gitlab-ce
Commits
cf292a3f
Commit
cf292a3f
authored
Jun 14, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve code clarity in pipeline create service
parent
e45fd5a1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
17 deletions
+41
-17
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+1
-1
app/services/create_commit_builds_service.rb
app/services/create_commit_builds_service.rb
+38
-14
spec/services/create_commit_builds_service_spec.rb
spec/services/create_commit_builds_service_spec.rb
+2
-2
No files found.
app/models/ci/pipeline.rb
View file @
cf292a3f
...
@@ -100,7 +100,7 @@ module Ci
...
@@ -100,7 +100,7 @@ module Ci
def
create_builds
(
user
,
trigger_request
=
nil
)
def
create_builds
(
user
,
trigger_request
=
nil
)
build_builds
(
user
,
'success'
,
trigger_request
)
build_builds
(
user
,
'success'
,
trigger_request
)
save
!
save
end
end
def
create_next_builds
(
build
)
def
create_next_builds
(
build
)
...
...
app/services/create_commit_builds_service.rb
View file @
cf292a3f
...
@@ -14,26 +14,50 @@ class CreateCommitBuildsService
...
@@ -14,26 +14,50 @@ class CreateCommitBuildsService
return
false
return
false
end
end
pipeline
=
Ci
::
Pipeline
.
new
(
project:
project
,
sha:
sha
,
ref:
ref
,
before_sha:
before_sha
,
tag:
tag
)
@
pipeline
=
Ci
::
Pipeline
.
new
(
project:
project
,
sha:
sha
,
ref:
ref
,
before_sha:
before_sha
,
tag:
tag
)
# Skip creating pipeline when no gitlab-ci.yml is found
##
unless
pipeline
.
ci_yaml_file
# Skip creating pipeline if no gitlab-ci.yml is found
return
pipeline
#
unless
@pipeline
.
ci_yaml_file
return
false
end
end
##
# Skip creating builds for commits that have [ci skip]
# Skip creating builds for commits that have [ci skip]
if
!
pipeline
.
skip_ci?
&&
pipeline
.
config_processor
# but save pipeline object
# Create builds for commit
#
unless
pipeline
.
build_builds
(
user
)
if
@pipeline
.
skip_ci?
pipeline
.
errors
.
add
(
:base
,
'No builds created'
)
return
save_pipeline!
return
pipeline
end
##
# Skip creating builds when CI config is invalid
# but save pipeline object
#
unless
@pipeline
.
config_processor
return
save_pipeline!
end
end
##
# Skip creating pipeline object if there are no builds for it.
#
unless
@pipeline
.
build_builds
(
user
)
@pipeline
.
errors
.
add
(
:base
,
'No builds created'
)
return
false
end
save_pipeline!
end
end
# Create a new pipeline
private
pipeline
.
save!
pipeline
.
touch
##
pipeline
# Create a new pipeline and touch object to calculate status
#
def
save_pipeline!
@pipeline
.
save!
@pipeline
.
touch
@pipeline
end
end
end
end
spec/services/create_commit_builds_service_spec.rb
View file @
cf292a3f
...
@@ -60,7 +60,7 @@ describe CreateCommitBuildsService, services: true do
...
@@ -60,7 +60,7 @@ describe CreateCommitBuildsService, services: true do
after:
'31das312'
,
after:
'31das312'
,
commits:
[{
message:
'Message'
}]
commits:
[{
message:
'Message'
}]
)
)
expect
(
result
).
not_to
be_persisted
expect
(
result
).
to
be_falsey
expect
(
Ci
::
Pipeline
.
count
).
to
eq
(
0
)
expect
(
Ci
::
Pipeline
.
count
).
to
eq
(
0
)
end
end
...
@@ -184,7 +184,7 @@ describe CreateCommitBuildsService, services: true do
...
@@ -184,7 +184,7 @@ describe CreateCommitBuildsService, services: true do
before:
'00000000'
,
before:
'00000000'
,
after:
'31das312'
,
after:
'31das312'
,
commits:
[{
message:
'some msg'
}])
commits:
[{
message:
'some msg'
}])
expect
(
result
).
not_to
be_persisted
expect
(
result
).
to
be_falsey
expect
(
Ci
::
Build
.
all
).
to
be_empty
expect
(
Ci
::
Build
.
all
).
to
be_empty
expect
(
Ci
::
Pipeline
.
count
).
to
eq
(
0
)
expect
(
Ci
::
Pipeline
.
count
).
to
eq
(
0
)
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