Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c8b16068
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,发现更多精彩内容 >>
提交
c8b16068
编写于
12月 21, 2016
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add specs for pipeline entity and improve factory
[ci skip]
上级
9f47d317
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
184 addition
and
26 deletion
+184
-26
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+4
-0
app/serializers/pipeline_entity.rb
app/serializers/pipeline_entity.rb
+30
-18
app/serializers/pipeline_serializer.rb
app/serializers/pipeline_serializer.rb
+8
-8
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+4
-0
spec/serializers/pipeline_entity_spec.rb
spec/serializers/pipeline_entity_spec.rb
+138
-0
未找到文件。
app/models/ci/pipeline.rb
浏览文件 @
c8b16068
...
...
@@ -290,6 +290,10 @@ module Ci
end
end
def
has_yaml_errors?
yaml_errors
.
present?
end
def
environments
builds
.
where
.
not
(
environment:
nil
).
success
.
pluck
(
:environment
).
uniq
end
...
...
app/serializers/pipeline_entity.rb
浏览文件 @
c8b16068
...
...
@@ -28,12 +28,10 @@ class PipelineEntity < Grape::Entity
expose
:flags
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
expose
:has_yaml_errors?
,
as: :yaml_errors
expose
:can_retry?
,
as: :retryable
expose
:can_cancel?
,
as: :cancelable
end
expose
:ref
do
...
...
@@ -41,31 +39,45 @@ class PipelineEntity < Grape::Entity
pipeline
.
ref
end
expose
:
url
do
|
pipeline
|
namespace_project_tree_
url
(
expose
:
path
do
|
pipeline
|
namespace_project_tree_
path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
id:
pipeline
.
ref
)
end
expose
:tag?
expose
:tag?
,
as: :tag
expose
:branch?
,
as: :branch
end
expose
:commit
,
using:
CommitEntity
expose
:yaml_errors
,
if:
->
(
pipeline
,
_
)
{
pipeline
.
has_yaml_errors?
}
expose
:retry_url
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
retryable?
&&
retry_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
expose
:retry_path
,
if:
proc
{
can_retry?
}
do
|
pipeline
|
retry_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
end
expose
:cancel_url
do
|
pipeline
|
can?
(
request
.
user
,
:update_pipeline
,
pipeline
.
project
)
&&
pipeline
.
cancelable?
&&
cancel_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
expose
:cancel_path
,
if:
proc
{
can_cancel?
}
do
|
pipeline
|
cancel_namespace_project_pipeline_path
(
pipeline
.
project
.
namespace
,
pipeline
.
project
,
pipeline
.
id
)
end
expose
:created_at
,
:updated_at
private
alias_method
:pipeline
,
:object
def
can_retry?
pipeline
.
retryable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
end
def
can_cancel?
pipeline
.
cancelable?
&&
can?
(
request
.
user
,
:update_pipeline
,
pipeline
)
end
end
app/serializers/pipeline_serializer.rb
浏览文件 @
c8b16068
...
...
@@ -3,14 +3,6 @@ class PipelineSerializer < BaseSerializer
include
API
::
Helpers
::
Pagination
Struct
.
new
(
'Pagination'
,
:request
,
:response
)
def
with_pagination
(
request
,
response
)
tap
{
@pagination
=
Struct
::
Pagination
.
new
(
request
,
response
)
}
end
def
paginate?
defined?
(
@pagination
)
end
def
represent
(
resource
,
opts
=
{})
if
paginate?
super
(
paginate
(
resource
),
opts
)
...
...
@@ -19,6 +11,14 @@ class PipelineSerializer < BaseSerializer
end
end
def
paginate?
defined?
(
@pagination
)
end
def
with_pagination
(
request
,
response
)
tap
{
@pagination
=
Struct
::
Pagination
.
new
(
request
,
response
)
}
end
private
# Methods needed by `API::Helpers::Pagination`
...
...
spec/factories/ci/pipelines.rb
浏览文件 @
c8b16068
...
...
@@ -31,6 +31,10 @@ FactoryGirl.define do
File
.
read
(
Rails
.
root
.
join
(
'spec/support/gitlab_stubs/gitlab_ci.yml'
))
end
end
# Populates pipeline with errors
#
pipeline
.
config_processor
if
evaluator
.
config
end
end
end
...
...
spec/serializers/pipeline_entity_spec.rb
0 → 100644
浏览文件 @
c8b16068
require
'spec_helper'
describe
PipelineEntity
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:request
)
{
double
(
'request'
)
}
before
do
allow
(
request
).
to
receive
(
:user
).
and_return
(
user
)
end
let
(
:entity
)
do
described_class
.
represent
(
pipeline
,
request:
request
)
end
describe
'#as_json'
do
subject
{
entity
.
as_json
}
context
'when pipeline is empty'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
it
'contains required fields'
do
expect
(
subject
).
to
include
:id
,
:user
,
:path
expect
(
subject
).
to
include
:ref
,
:commit
expect
(
subject
).
to
include
:updated_at
,
:created_at
end
it
'contains details'
do
expect
(
subject
).
to
include
:details
expect
(
subject
[
:details
])
.
to
include
:duration
,
:finished_at
expect
(
subject
[
:details
])
.
to
include
:stages
,
:artifacts
,
:manual_actions
expect
(
subject
[
:details
][
:status
]).
to
include
:icon
,
:text
,
:label
end
it
'contains flags'
do
expect
(
subject
).
to
include
:flags
expect
(
subject
[
:flags
])
.
to
include
:latest
,
:triggered
,
:stuck
,
:yaml_errors
,
:retryable
,
:cancelable
end
end
context
'when pipeline is retryable'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
status: :success
,
project:
project
)
end
before
do
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
)
end
context
'user has ability to retry pipeline'
do
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'retryable flag is true'
do
expect
(
subject
[
:flags
][
:retryable
]).
to
eq
true
end
it
'contains retry path'
do
expect
(
subject
[
:retry_path
]).
to
be_present
end
end
context
'user does not have ability to retry pipeline'
do
it
'retryable flag is false'
do
expect
(
subject
[
:flags
][
:retryable
]).
to
eq
false
end
it
'does not contain retry path'
do
expect
(
subject
).
not_to
have_key
(
:retry_path
)
end
end
end
context
'when pipeline is cancelable'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
status: :running
,
project:
project
)
end
before
do
create
(
:ci_build
,
:pending
,
pipeline:
pipeline
)
end
context
'user has ability to cancel pipeline'
do
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'cancelable flag is true'
do
expect
(
subject
[
:flags
][
:cancelable
]).
to
eq
true
end
it
'contains cancel path'
do
expect
(
subject
[
:cancel_path
]).
to
be_present
end
end
context
'user does not have ability to cancel pipeline'
do
it
'cancelable flag is false'
do
expect
(
subject
[
:flags
][
:cancelable
]).
to
eq
false
end
it
'does not contain cancel path'
do
expect
(
subject
).
not_to
have_key
(
:cancel_path
)
end
end
end
context
'when pipeline has YAML errors'
do
let
(
:pipeline
)
do
create
(
:ci_pipeline
,
config:
{
rspec:
{
invalid: :value
}
})
end
it
'contains flag that indicates there are errors'
do
expect
(
subject
[
:flags
][
:yaml_errors
]).
to
be
true
end
it
'contains information about error'
do
expect
(
subject
[
:yaml_errors
]).
to
be_present
end
end
context
'when pipeline does not have YAML errors'
do
let
(
:pipeline
)
{
create
(
:ci_empty_pipeline
)
}
it
'contains flag that indicates there are no errors'
do
expect
(
subject
[
:flags
][
:yaml_errors
]).
to
be
false
end
it
'does not contain field that normally holds an error'
do
expect
(
subject
).
not_to
have_key
(
:yaml_errors
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录