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
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
25 deletions
+27
-25
app/services/ci/create_builds_service.rb
app/services/ci/create_builds_service.rb
+2
-1
app/services/create_commit_builds_service.rb
app/services/create_commit_builds_service.rb
+18
-17
spec/models/ci/commit_spec.rb
spec/models/ci/commit_spec.rb
+3
-3
spec/services/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
...
@@ -36,7 +36,8 @@ module Ci
:stage
,
:stage
,
:stage_idx
)
:stage_idx
)
build_attrs
.
merge!
(
ref:
@commit
.
ref
,
build_attrs
.
merge!
(
commit:
@commit
,
ref:
@commit
.
ref
,
tag:
@commit
.
tag
,
tag:
@commit
.
tag
,
trigger_request:
trigger_request
,
trigger_request:
trigger_request
,
user:
user
,
user:
user
,
...
...
app/services/create_commit_builds_service.rb
View file @
8e811f2c
class
CreateCommitBuildsService
class
CreateCommitBuildsService
def
execute
(
project
,
user
,
params
)
def
execute
(
project
,
user
,
params
)
return
false
unless
project
.
builds_enabled?
return
unless
project
.
builds_enabled?
before_sha
=
params
[
:checkout_sha
]
||
params
[
:before
]
before_sha
=
params
[
:checkout_sha
]
||
params
[
:before
]
sha
=
params
[
:checkout_sha
]
||
params
[
:after
]
sha
=
params
[
:checkout_sha
]
||
params
[
:after
]
origin_ref
=
params
[
:ref
]
origin_ref
=
params
[
:ref
]
unless
origin_ref
&&
sha
.
present?
return
false
end
ref
=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
ref
=
Gitlab
::
Git
.
ref_name
(
origin_ref
)
tag
=
Gitlab
::
Git
.
tag_ref?
(
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
)
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
unless
commit
.
ci_yaml_file
return
false
commit
.
errors
.
add
(
:base
,
'No .gitlab-ci.yml file found'
)
return
commit
end
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]
# Create builds for commit and
unless
commit
.
skip_ci?
# skip saving pipeline when there are no builds
# Create builds for commit and
unless
commit
.
create_builds
(
user
)
# skip saving pipeline when there are no builds
# Save object when there are yaml errors
return
false
unless
commit
.
create_builds
(
user
)
unless
commit
.
yaml_errors
.
present?
commit
.
errors
.
add
(
:base
,
'No builds created'
)
return
commit
end
end
end
# Create a new ci_commit
# Create a new ci_commit
commit
.
save!
commit
.
save!
commit
.
touch
commit
commit
end
end
end
end
spec/models/ci/commit_spec.rb
View file @
8e811f2c
...
@@ -351,8 +351,8 @@ describe Ci::Commit, models: true do
...
@@ -351,8 +351,8 @@ describe Ci::Commit, models: true do
end
end
describe
'#update_state!'
do
describe
'#update_state!'
do
it
'execute update_state
!
after touching object'
do
it
'execute update_state after touching object'
do
expect
(
commit
).
to
receive
(
:update_state
!
).
and_return
(
true
)
expect
(
commit
).
to
receive
(
:update_state
).
and_return
(
true
)
commit
.
touch
commit
.
touch
end
end
...
@@ -360,7 +360,7 @@ describe Ci::Commit, models: true do
...
@@ -360,7 +360,7 @@ describe Ci::Commit, models: true do
let
(
:commit_status
)
{
build
:commit_status
,
commit:
commit
}
let
(
:commit_status
)
{
build
:commit_status
,
commit:
commit
}
it
'execute update_state after saving dependent object'
do
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
commit_status
.
save
end
end
end
end
...
...
spec/services/create_commit_builds_service_spec.rb
View file @
8e811f2c
...
@@ -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
).
to
be_falsey
expect
(
result
).
not_to
be_persisted
expect
(
Ci
::
Commit
.
count
).
to
eq
(
0
)
expect
(
Ci
::
Commit
.
count
).
to
eq
(
0
)
end
end
...
@@ -174,7 +174,7 @@ describe CreateCommitBuildsService, services: true do
...
@@ -174,7 +174,7 @@ describe CreateCommitBuildsService, services: true do
context
'when there are no jobs for this pipeline'
do
context
'when there are no jobs for this pipeline'
do
before
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
)
stub_ci_commit_yaml_file
(
config
)
end
end
...
@@ -184,9 +184,9 @@ describe CreateCommitBuildsService, services: true do
...
@@ -184,9 +184,9 @@ 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
false
expect
(
Ci
::
Build
.
all
).
to
be_empty
expect
(
Ci
::
Build
.
all
).
to
be_empty
expect
(
Ci
::
Commit
.
count
).
to
eq
(
0
)
end
end
end
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