Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
164b1df5
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
164b1df5
编写于
10月 11, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract ensure stage service from commit status class
上级
e2828a60
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
27 deletion
+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
未找到文件。
app/models/commit_status.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录