Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
79ea01bf
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 搜索 >>
提交
79ea01bf
编写于
3月 02, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor code related to pipeline blocking actions
上级
f9a18143
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
36 addition
and
30 deletion
+36
-30
app/models/ci/build.rb
app/models/ci/build.rb
+14
-5
app/models/commit_status.rb
app/models/commit_status.rb
+5
-5
app/models/concerns/has_status.rb
app/models/concerns/has_status.rb
+9
-12
app/services/ci/process_pipeline_service.rb
app/services/ci/process_pipeline_service.rb
+2
-2
lib/gitlab/ci/config/entry/job.rb
lib/gitlab/ci/config/entry/job.rb
+0
-4
spec/factories/ci/builds.rb
spec/factories/ci/builds.rb
+4
-0
spec/services/ci/process_pipeline_service_spec.rb
spec/services/ci/process_pipeline_service_spec.rb
+2
-2
未找到文件。
app/models/ci/build.rb
浏览文件 @
79ea01bf
...
...
@@ -64,7 +64,7 @@ module Ci
state_machine
:status
do
event
:block
do
transition
:created
=>
:
manual
,
if:
->
()
{
self
.
when
==
'manual'
}
transition
:created
=>
:
blocked
end
after_transition
any
=>
[
:pending
]
do
|
build
|
...
...
@@ -103,11 +103,20 @@ module Ci
end
def
playable?
project
.
builds_enabled?
&&
commands
.
present?
&&
manual?
project
.
builds_enabled?
&&
has_commands?
&&
manual?
&&
(
skipped?
||
blocked?
)
end
def
is_blocking?
playable?
&&
!
allow_failure?
def
manual?
self
.
when
==
'manual'
end
def
barrier?
manual?
&&
!
allow_failure?
end
def
has_commands?
commands
.
present?
end
def
play
(
current_user
)
...
...
@@ -126,7 +135,7 @@ module Ci
end
def
retryable?
project
.
builds_enabled?
&&
commands
.
present
?
&&
project
.
builds_enabled?
&&
has_commands
?
&&
(
success?
||
failed?
||
canceled?
)
end
...
...
app/models/commit_status.rb
浏览文件 @
79ea01bf
...
...
@@ -25,13 +25,13 @@ class CommitStatus < ActiveRecord::Base
end
scope
:failed_but_allowed
,
->
do
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
,
:
manual
])
where
(
allow_failure:
true
,
status:
[
:failed
,
:canceled
,
:
blocked
])
end
scope
:exclude_ignored
,
->
do
# We want to ignore failed_but_allowed jobs
where
(
"allow_failure = ? OR status IN (?)"
,
false
,
all_state_names
-
[
:failed
,
:canceled
,
:
manual
])
false
,
all_state_names
-
[
:failed
,
:canceled
,
:
blocked
])
end
scope
:retried
,
->
{
where
.
not
(
id:
latest
)
}
...
...
@@ -42,11 +42,11 @@ class CommitStatus < ActiveRecord::Base
state_machine
:status
do
event
:enqueue
do
transition
[
:created
,
:skipped
,
:
manual
]
=>
:pending
transition
[
:created
,
:skipped
,
:
blocked
]
=>
:pending
end
event
:process
do
transition
[
:skipped
,
:
manual
]
=>
:created
transition
[
:skipped
,
:
blocked
]
=>
:created
end
event
:run
do
...
...
@@ -66,7 +66,7 @@ class CommitStatus < ActiveRecord::Base
end
event
:cancel
do
transition
[
:created
,
:pending
,
:running
,
:
manual
]
=>
:canceled
transition
[
:created
,
:pending
,
:running
,
:
blocked
]
=>
:canceled
end
before_transition
created:
[
:pending
,
:running
]
do
|
commit_status
|
...
...
app/models/concerns/has_status.rb
浏览文件 @
79ea01bf
...
...
@@ -2,23 +2,20 @@ module HasStatus
extend
ActiveSupport
::
Concern
DEFAULT_STATUS
=
'created'
.
freeze
AVAILABLE_STATUSES
=
%w[created pending running success failed canceled skipped
manual
]
.
freeze
AVAILABLE_STATUSES
=
%w[created pending running success failed canceled skipped
blocked
]
.
freeze
STARTED_STATUSES
=
%w[running success failed skipped]
.
freeze
ACTIVE_STATUSES
=
%w[pending running
manual
]
.
freeze
ACTIVE_STATUSES
=
%w[pending running
blocked
]
.
freeze
COMPLETED_STATUSES
=
%w[success failed canceled skipped]
.
freeze
ORDERED_STATUSES
=
%w[failed pending running canceled success skipped]
.
freeze
class_methods
do
def
status_sql
scope
=
if
respond_to?
(
:exclude_ignored
)
exclude_ignored
else
all
end
scope
=
respond_to?
(
:exclude_ignored
)
?
exclude_ignored
:
all
builds
=
scope
.
select
(
'count(*)'
).
to_sql
created
=
scope
.
created
.
select
(
'count(*)'
).
to_sql
success
=
scope
.
success
.
select
(
'count(*)'
).
to_sql
manual
=
scope
.
manual
.
select
(
'count(*)'
).
to_sql
blocked
=
scope
.
blocked
.
select
(
'count(*)'
).
to_sql
pending
=
scope
.
pending
.
select
(
'count(*)'
).
to_sql
running
=
scope
.
running
.
select
(
'count(*)'
).
to_sql
skipped
=
scope
.
skipped
.
select
(
'count(*)'
).
to_sql
...
...
@@ -32,7 +29,7 @@ module HasStatus
WHEN (
#{
builds
}
)=(
#{
success
}
)+(
#{
skipped
}
)+(
#{
canceled
}
) THEN 'canceled'
WHEN (
#{
builds
}
)=(
#{
created
}
)+(
#{
skipped
}
)+(
#{
pending
}
) THEN 'pending'
WHEN (
#{
running
}
)+(
#{
pending
}
)+(
#{
created
}
)>0 THEN 'running'
WHEN (
#{
manual
}
)>0 THEN 'manual
'
WHEN (
#{
blocked
}
)>0 THEN 'blocked
'
ELSE 'failed'
END)"
end
...
...
@@ -65,7 +62,7 @@ module HasStatus
state
:success
,
value:
'success'
state
:canceled
,
value:
'canceled'
state
:skipped
,
value:
'skipped'
state
:
manual
,
value:
'manual
'
state
:
blocked
,
value:
'blocked
'
end
scope
:created
,
->
{
where
(
status:
'created'
)
}
...
...
@@ -76,13 +73,13 @@ module HasStatus
scope
:failed
,
->
{
where
(
status:
'failed'
)
}
scope
:canceled
,
->
{
where
(
status:
'canceled'
)
}
scope
:skipped
,
->
{
where
(
status:
'skipped'
)
}
scope
:
manual
,
->
{
where
(
status:
'manual
'
)
}
scope
:
blocked
,
->
{
where
(
status:
'blocked
'
)
}
scope
:running_or_pending
,
->
{
where
(
status:
[
:running
,
:pending
])
}
scope
:finished
,
->
{
where
(
status:
[
:success
,
:failed
,
:canceled
])
}
scope
:failed_or_canceled
,
->
{
where
(
status:
[
:failed
,
:canceled
])
}
scope
:cancelable
,
->
do
where
(
status:
[
:running
,
:pending
,
:created
,
:
manual
])
where
(
status:
[
:running
,
:pending
,
:created
,
:
blocked
])
end
end
...
...
app/services/ci/process_pipeline_service.rb
浏览文件 @
79ea01bf
...
...
@@ -35,9 +35,9 @@ module Ci
if
valid_statuses_for_when
(
build
.
when
).
include?
(
current_status
)
build
.
enqueue
true
elsif
build
.
can_block
?
elsif
build
.
barrier
?
build
.
block
build
.
is_blocking?
false
else
build
.
skip
false
...
...
lib/gitlab/ci/config/entry/job.rb
浏览文件 @
79ea01bf
...
...
@@ -104,10 +104,6 @@ module Gitlab
(
before_script_value
.
to_a
+
script_value
.
to_a
).
join
(
"
\n
"
)
end
def
allow_failure
super
||
self
.
when
==
'manual'
end
private
def
inherit!
(
deps
)
...
...
spec/factories/ci/builds.rb
浏览文件 @
79ea01bf
...
...
@@ -71,6 +71,10 @@ FactoryGirl.define do
allow_failure
true
end
trait
:ignored
do
allowed_to_fail
end
trait
:playable
do
skipped
manual
...
...
spec/services/ci/process_pipeline_service_spec.rb
浏览文件 @
79ea01bf
...
...
@@ -68,9 +68,9 @@ describe Ci::ProcessPipelineService, :services do
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'test'
,
stage_idx:
1
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'test_failure'
,
stage_idx:
2
,
when:
'on_failure'
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'deploy'
,
stage_idx:
3
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'production'
,
stage_idx:
3
,
when:
'manual'
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'production'
,
stage_idx:
3
,
when:
'manual'
,
allow_failure:
true
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'cleanup'
,
stage_idx:
4
,
when:
'always'
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'clear cache'
,
stage_idx:
4
,
when:
'manual'
)
create
(
:ci_build
,
:created
,
pipeline:
pipeline
,
name:
'clear cache'
,
stage_idx:
4
,
when:
'manual'
,
allow_failure:
true
)
end
context
'when builds are successful'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录