Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
b0c6037a
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,发现更多精彩内容 >>
提交
b0c6037a
编写于
11月 10, 2016
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine incremental pipeline serializer
上级
f41c3c02
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
80 addition
and
20 deletion
+80
-20
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+6
-2
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+33
-18
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+5
-0
spec/serializers/pipeline_serializer_spec.rb
spec/serializers/pipeline_serializer_spec.rb
+36
-0
未找到文件。
app/controllers/projects/pipelines_controller.rb
浏览文件 @
b0c6037a
...
...
@@ -17,8 +17,12 @@ class Projects::PipelinesController < Projects::ApplicationController
format
.
html
format
.
json
do
render
json:
{
pipelines:
PipelineSerializer
.
new
(
project:
@project
).
represent
(
@pipelines
,
current_user:
current_user
,
last_updated:
@last_updated
),
pipelines:
PipelineSerializer
.
incremental
(
project:
@project
,
user:
@current_user
,
last_updated:
@last_updated
)
.
represent
updated_at:
Time
.
now
,
count:
{
all:
@pipelines_count
,
...
...
app/serializers/pipeline_entity.rb
浏览文件 @
b0c6037a
...
...
@@ -2,7 +2,8 @@ class PipelineEntity < Grape::Entity
include
RequestAwareEntity
expose
:id
expose
:user
,
if:
->
(
pipeline
,
opts
)
{
created?
(
pipeline
,
opts
)
},
using:
UserEntity
expose
:user
,
if:
proc
{
created_exposure?
},
using:
UserEntity
expose
:url
do
|
pipeline
|
namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
...
...
@@ -10,7 +11,7 @@ class PipelineEntity < Grape::Entity
pipeline
)
end
expose
:details
,
if:
->
(
pipeline
,
opts
)
{
updated?
(
pipeline
,
opts
)
}
do
expose
:details
,
if:
proc
{
updated_exposure?
}
do
expose
:status
expose
:duration
expose
:finished_at
...
...
@@ -19,18 +20,20 @@ class PipelineEntity < Grape::Entity
expose
:manual_actions
,
using:
PipelineActionEntity
end
expose
:flags
,
if:
->
(
pipeline
,
opts
)
{
created?
(
pipeline
,
opts
)
}
do
expose
:flags
,
if:
proc
{
created_exposure?
}
do
expose
:latest?
,
as: :latest
expose
:triggered?
,
as: :triggered
expose
:yaml_errors?
,
as: :yaml_errors
do
|
pipeline
|
pipeline
.
yaml_errors
.
present?
end
expose
:stuck?
,
as: :stuck
do
|
pipeline
|
pipeline
.
builds
.
any?
(
&
:stuck?
)
end
end
expose
:ref
,
if:
->
(
pipeline
,
opts
)
{
created?
(
pipeline
,
opts
)
}
do
expose
:ref
,
if:
proc
{
updated_exposure?
}
do
expose
:name
do
|
pipeline
|
pipeline
.
ref
end
...
...
@@ -45,31 +48,43 @@ class PipelineEntity < Grape::Entity
expose
:tag?
end
expose
:commit
,
if:
->
(
pipeline
,
opts
)
{
created?
(
pipeline
,
opts
)
},
using:
CommitEntity
expose
:commit
,
if:
proc
{
created_exposure?
},
using:
CommitEntity
expose
:retry_url
,
if:
->
(
pipeline
,
opts
)
{
updated?
(
pipeline
,
opts
)
}
do
|
pipeline
|
can?
(
current_
user
,
:update_pipeline
,
pipeline
.
project
)
&&
expose
:retry_url
,
if:
proc
{
updated_exposure?
}
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
retryable?
&&
retry_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
retry_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
end
expose
:cancel_url
,
if:
->
(
pipeline
,
opts
)
{
updated?
(
pipeline
,
opts
)
}
do
|
pipeline
|
can?
(
current_
user
,
:update_pipeline
,
pipeline
.
project
)
&&
expose
:cancel_url
,
if:
proc
{
updated_exposure?
}
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
cancelable?
&&
cancel_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
cancel_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
end
def
created_exposure?
!
incremental?
||
created?
end
def
updated_exposure?
!
incremental?
||
updated?
end
private
def
incremental?
options
[
:incremental
]
end
def
last_updated
(
opts
)
opts
.
fetch
(
:last_updated
)
def
last_updated
opt
ion
s
.
fetch
(
:last_updated
)
end
def
created?
(
pipeline
,
opts
)
!
last_updated
(
opts
)
||
pipeline
.
created_at
>
last_updated
(
opts
)
def
updated?
@object
.
updated_at
>
last_updated
end
def
updated?
(
pipeline
,
opts
)
!
last_updated
(
opts
)
||
pipeline
.
updated_at
>
last_updated
(
opts
)
def
created?
@object
.
created_at
>
last_updated
end
end
app/serializers/pipeline_serializer.rb
浏览文件 @
b0c6037a
class
PipelineSerializer
<
BaseSerializer
entity
PipelineEntity
def
incremental
(
resource
,
last_updated
)
represent
(
resource
,
incremental:
true
,
last_updated:
last_updated
)
end
end
spec/serializers/pipeline_serializer_spec.rb
0 → 100644
浏览文件 @
b0c6037a
require
'spec_helper'
describe
PipelineSerializer
do
let
(
:serializer
)
do
described_class
.
new
(
user:
user
)
end
let
(
:pipelines
)
do
create_list
(
:ci_pipeline
,
2
)
end
let
(
:user
)
{
create
(
:user
)
}
context
'when using incremental serializer'
do
let
(
:json
)
do
serializer
.
incremental
(
pipelines
,
time
).
as_json
end
context
'when pipeline has been already updated'
do
let
(
:time
)
{
Time
.
now
}
it
'exposes only minimal information'
do
expect
(
json
.
first
.
keys
).
to
contain_exactly
(
:id
,
:url
)
expect
(
json
.
second
.
keys
).
to
contain_exactly
(
:id
,
:url
)
end
end
context
'when pipeline updated in the meantime'
do
let
(
:time
)
{
Time
.
now
-
10
.
minutes
}
it
'exposes new data incrementally'
do
expect
(
json
.
first
.
keys
.
count
).
to
eq
9
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录