BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8e811f2c
Commit
8e811f2c
authored
Jun 02, 2016
by
Kamil Trzcinski
Committed by
Grzegorz Bizon
Jun 03, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update CreateCommitBuildsService to pass tests
parent
c6bce7e6
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
25 deletions
+27
-25
create_builds_service.rb
app/services/ci/create_builds_service.rb
+2
-1
create_commit_builds_service.rb
app/services/create_commit_builds_service.rb
+18
-17
commit_spec.rb
spec/models/ci/commit_spec.rb
+3
-3
create_commit_builds_service_spec.rb
spec/services/create_commit_builds_service_spec.rb
+4
-4
No files found.
app/services/ci/create_builds_service.rb
View file @
8e811f2c
...
...
@@ -36,7 +36,8 @@ module Ci
:stage
,
:stage_idx
)
build_attrs
.
merge!
(
ref:
@commit
.
ref
,
build_attrs
.
merge!
(
commit:
@commit
,
ref:
@commit
.
ref
,
tag:
@commit
.
tag
,
trigger_request:
trigger_request
,
user:
user
,
...
...
app/services/create_commit_builds_service.rb
View file @
8e811f2c
class
CreateCommitBuildsService
def
execute
(
project
,
user
,
params
)
return
false
unless
project
.
builds_enabled?
return
unless
project
.
builds_enabled?
before_sha
=
params
[
:checkout_sha
]
||
params
[
:before
]
sha
=
params
[
:checkout_sha
]
||
params
[
:after
]
origin_ref
=
params
[
:ref
]
unless
origin_ref
&&
sha
.
present?
return
false
end
ref
=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
tag
=
Gitlab
::
Git
.
tag_ref?
(
origin_ref
)
# Skip branch removal
if
sha
==
Gitlab
::
Git
::
BLANK_SHA
return
false
end
commit
=
Ci
::
Commit
.
new
(
project:
project
,
sha:
sha
,
ref:
ref
,
before_sha:
before_sha
,
tag:
tag
)
# Skip creating ci_commit when no gitlab-ci.yml is found
unless
commit
.
ci_yaml_file
return
false
commit
.
errors
.
add
(
:base
,
'No .gitlab-ci.yml file found'
)
return
commit
end
# Make object as skipped
if
commit
.
skip_ci?
commit
.
status
=
'skipped'
commit
.
save
return
commit
end
# Skip creating builds for commits that have [ci skip]
unless
commit
.
skip_ci?
# Create builds for commit and
# skip saving pipeline when there are no builds
return
false
unless
commit
.
create_builds
(
user
)
# Create builds for commit and
# skip saving pipeline when there are no builds
unless
commit
.
create_builds
(
user
)
# Save object when there are yaml errors
unless
commit
.
yaml_errors
.
present?
commit
.
errors
.
add
(
:base
,
'No builds created'
)
return
commit
end
end
# Create a new ci_commit
commit
.
save!
commit
.
touch
commit
end
end
spec/models/ci/commit_spec.rb
View file @
8e811f2c
...
...
@@ -351,8 +351,8 @@ describe Ci::Commit, models: true do
end
describe
'#update_state!'
do
it
'execute update_state
!
after touching object'
do
expect
(
commit
).
to
receive
(
:update_state
!
).
and_return
(
true
)
it
'execute update_state after touching object'
do
expect
(
commit
).
to
receive
(
:update_state
).
and_return
(
true
)
commit
.
touch
end
...
...
@@ -360,7 +360,7 @@ describe Ci::Commit, models: true do
let
(
:commit_status
)
{
build
:commit_status
,
commit:
commit
}
it
'execute update_state after saving dependent object'
do
expect
(
commit
).
to
receive
(
:update_state
!
).
and_return
(
true
)
expect
(
commit
).
to
receive
(
:update_state
).
and_return
(
true
)
commit_status
.
save
end
end
...
...
spec/services/create_commit_builds_service_spec.rb
View file @
8e811f2c
...
...
@@ -60,7 +60,7 @@ describe CreateCommitBuildsService, services: true do
after:
'31das312'
,
commits:
[{
message:
'Message'
}]
)
expect
(
result
).
to
be_falsey
expect
(
result
).
not_to
be_persisted
expect
(
Ci
::
Commit
.
count
).
to
eq
(
0
)
end
...
...
@@ -174,7 +174,7 @@ describe CreateCommitBuildsService, services: true do
context
'when there are no jobs for this pipeline'
do
before
do
config
=
YAML
.
dump
({
test:
{
deploy
:
'ls'
,
only:
[
'feature'
]
}
})
config
=
YAML
.
dump
({
test:
{
script
:
'ls'
,
only:
[
'feature'
]
}
})
stub_ci_commit_yaml_file
(
config
)
end
...
...
@@ -184,9 +184,9 @@ describe CreateCommitBuildsService, services: true do
before:
'00000000'
,
after:
'31das312'
,
commits:
[{
message:
'some msg'
}])
expect
(
result
).
to
be
false
expect
(
result
).
not_to
be_persisted
expect
(
Ci
::
Build
.
all
).
to
be_empty
expect
(
Ci
::
Commit
.
count
).
to
eq
(
0
)
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