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
164b1df5
Commit
164b1df5
authored
Oct 11, 2017
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract ensure stage service from commit status class
parent
e2828a60
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
27 deletions
+43
-27
app/models/commit_status.rb
app/models/commit_status.rb
+3
-27
app/services/ci/ensure_stage_service.rb
app/services/ci/ensure_stage_service.rb
+39
-0
spec/factories/commit_statuses.rb
spec/factories/commit_statuses.rb
+1
-0
No files found.
app/models/commit_status.rb
View file @
164b1df5
...
...
@@ -50,13 +50,9 @@ class CommitStatus < ActiveRecord::Base
#
# These are pages deployments and external statuses.
#
before_create
do
|
status
|
next
if
status
.
stage_id
.
present?
||
importing?
ensure_pipeline_stage!
do
|
stage
|
status
.
run_after_commit
do
StageUpdateWorker
.
perform_async
(
stage
.
id
)
end
before_create
unless: :importing?
do
Ci
::
EnsureStageService
.
new
(
project
,
user
).
execute
(
self
)
do
|
stage
|
self
.
run_after_commit
{
StageUpdateWorker
.
perform_async
(
stage
.
id
)
}
end
end
...
...
@@ -188,24 +184,4 @@ class CommitStatus < ActiveRecord::Base
v
=~
/\d+/
?
v
.
to_i
:
v
end
end
private
def
ensure_pipeline_stage!
(
find_stage
||
create_stage!
).
tap
do
|
stage
|
self
.
stage_id
=
stage
.
id
yield
stage
end
end
def
find_stage
pipeline
.
stages
.
find_by
(
name:
stage
)
end
def
create_stage!
Ci
::
Stage
.
create!
(
name:
stage
,
pipeline:
pipeline
,
project:
project
)
end
end
app/services/ci/ensure_stage_service.rb
0 → 100644
View file @
164b1df5
module
Ci
##
# We call this service everytime we persist a CI/CD job.
#
# In most cases a job should already have a stage assigned, but in cases it
# doesn't have we need to either find existing one or create a brand new
# stage.
#
class
EnsureStageService
<
BaseService
def
execute
(
build
)
@build
=
build
return
if
build
.
stage_id
.
present?
return
if
build
.
invalid?
ensure_stage
.
tap
do
|
stage
|
build
.
stage_id
=
stage
.
id
yield
stage
if
block_given?
end
end
private
def
ensure_stage
find_stage
||
create_stage
end
def
find_stage
@build
.
pipeline
.
stages
.
find_by
(
name:
@build
.
stage
)
end
def
create_stage
Ci
::
Stage
.
create!
(
name:
@build
.
stage
,
pipeline:
@build
.
pipeline
,
project:
@build
.
project
)
end
end
end
spec/factories/commit_statuses.rb
View file @
164b1df5
FactoryGirl
.
define
do
factory
:commit_status
,
class:
CommitStatus
do
name
'default'
stage
'test'
status
'success'
description
'commit status'
pipeline
factory: :ci_pipeline_with_one_job
...
...
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