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
af2f56f8
Commit
af2f56f8
authored
Jun 02, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor ci commit pipeline to prevent implicit saves
parent
3f4ac2ff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
27 deletions
+17
-27
app/models/ci/commit.rb
app/models/ci/commit.rb
+4
-12
app/services/ci/create_pipeline_service.rb
app/services/ci/create_pipeline_service.rb
+11
-13
app/services/create_commit_builds_service.rb
app/services/create_commit_builds_service.rb
+1
-1
spec/services/create_commit_builds_service_spec.rb
spec/services/create_commit_builds_service_spec.rb
+1
-1
No files found.
app/models/ci/commit.rb
View file @
af2f56f8
...
...
@@ -13,7 +13,7 @@ module Ci
validate
:valid_commit_sha
# Invalidate object and save if when touched
after_touch
:update_state
after_touch
:update_state
!
def
self
.
truncate_sha
(
sha
)
sha
[
0
...
8
]
...
...
@@ -135,10 +135,10 @@ module Ci
@config_processor
||=
begin
Ci
::
GitlabCiYamlProcessor
.
new
(
ci_yaml_file
,
project
.
path_with_namespace
)
rescue
Ci
::
GitlabCiYamlProcessor
::
ValidationError
,
Psych
::
SyntaxError
=>
e
s
ave_yaml_error
(
e
.
message
)
s
elf
.
yaml_errors
=
(
e
.
message
)
nil
rescue
s
ave_yaml_error
(
"Undefined error"
)
s
elf
.
yaml_errors
=
'Undefined error'
nil
end
end
...
...
@@ -159,9 +159,7 @@ module Ci
git_commit_message
=~
/(\[ci skip\])/
if
git_commit_message
end
private
def
update_state
def
update_state!
statuses
.
reload
self
.
status
=
if
yaml_errors
.
blank?
statuses
.
latest
.
status
||
'skipped'
...
...
@@ -173,11 +171,5 @@ module Ci
self
.
duration
=
statuses
.
latest
.
duration
save
end
def
save_yaml_error
(
error
)
return
if
self
.
yaml_errors?
self
.
yaml_errors
=
error
update_state
end
end
end
app/services/ci/create_pipeline_service.rb
View file @
af2f56f8
...
...
@@ -8,7 +8,9 @@ module Ci
return
pipeline
end
unless
commit
if
commit
pipeline
.
sha
=
commit
.
id
else
pipeline
.
errors
.
add
(
:base
,
'Commit not found'
)
return
pipeline
end
...
...
@@ -18,22 +20,18 @@ module Ci
return
pipeline
end
begin
Ci
::
Commit
.
transaction
do
pipeline
.
sha
=
commit
.
id
unless
pipeline
.
config_processor
pipeline
.
errors
.
add
(
:base
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
)
return
pipeline
end
unless
pipeline
.
config_processor
pipeline
.
errors
.
add
(
:base
,
pipeline
.
yaml_errors
||
'Missing .gitlab-ci.yml file'
)
raise
ActiveRecord
::
Rollback
end
pipeline
.
save!
pipeline
.
save!
pipeline
.
create_builds
(
current_user
)
end
rescue
pipeline
.
errors
.
add
(
:base
,
'The pipeline could not be created. Please try again.'
)
unless
pipeline
.
create_builds
(
current_user
)
pipeline
.
errors
.
add
(
:base
,
'No builds for this pipeline.'
)
end
pipeline
.
update_state!
pipeline
end
...
...
app/services/create_commit_builds_service.rb
View file @
af2f56f8
...
...
@@ -34,7 +34,7 @@ class CreateCommitBuildsService
commit
.
create_builds
(
user
)
end
commit
.
touch
commit
.
update_state!
commit
end
end
spec/services/create_commit_builds_service_spec.rb
View file @
af2f56f8
...
...
@@ -81,7 +81,7 @@ describe CreateCommitBuildsService, services: true do
expect
(
commit
.
yaml_errors
).
not_to
be_nil
end
describe
:ci_skip?
do
context
'when commit contains a [ci skip] directive'
do
let
(
:message
)
{
"some message[ci skip]"
}
before
do
...
...
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