Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
e9d94451
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 搜索 >>
提交
e9d94451
编写于
2月 21, 2017
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- Add new parameters for Pipeline API
- Expand PipelinesFinder functions
上级
9fd1a35f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
104 addition
and
26 deletion
+104
-26
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+5
-5
app/finders/pipelines_finder.rb
app/finders/pipelines_finder.rb
+88
-20
lib/api/pipelines.rb
lib/api/pipelines.rb
+11
-1
未找到文件。
app/controllers/projects/pipelines_controller.rb
浏览文件 @
e9d94451
...
...
@@ -9,19 +9,19 @@ class Projects::PipelinesController < Projects::ApplicationController
def
index
@scope
=
params
[
:scope
]
@pipelines
=
PipelinesFinder
.
new
(
project
)
.
execute
(
scope:
@scope
)
.
new
(
project
,
scope:
@scope
)
.
execute
.
page
(
params
[
:page
])
.
per
(
30
)
@running_count
=
PipelinesFinder
.
new
(
project
).
execute
(
scope:
'running'
)
.
count
.
new
(
project
,
scope:
'running'
).
execute
.
count
@pending_count
=
PipelinesFinder
.
new
(
project
).
execute
(
scope:
'pending'
)
.
count
.
new
(
project
,
scope:
'pending'
).
execute
.
count
@finished_count
=
PipelinesFinder
.
new
(
project
).
execute
(
scope:
'finished'
)
.
count
.
new
(
project
,
scope:
'finished'
).
execute
.
count
@pipelines_count
=
PipelinesFinder
.
new
(
project
).
execute
.
count
...
...
app/finders/pipelines_finder.rb
浏览文件 @
e9d94451
class
PipelinesFinder
attr_reader
:project
,
:pipelines
attr_reader
:project
,
:pipelines
,
:params
def
initialize
(
project
)
def
initialize
(
project
,
params
=
{}
)
@project
=
project
@pipelines
=
project
.
pipelines
@params
=
params
end
def
execute
(
scope:
nil
)
scoped_pipelines
=
case
scope
when
'running'
pipelines
.
running
when
'pending'
pipelines
.
pending
when
'finished'
pipelines
.
finished
when
'branches'
from_ids
(
ids_for_ref
(
branches
))
when
'tags'
from_ids
(
ids_for_ref
(
tags
))
else
pipelines
end
scoped_pipelines
.
order
(
id: :desc
)
def
execute
items
=
pipelines
items
=
by_scope
(
items
)
items
=
by_status
(
items
)
items
=
by_ref
(
items
)
items
=
by_user
(
items
)
items
=
by_duration
(
items
)
items
=
by_yaml_error
(
items
)
order_and_sort
(
items
)
end
private
...
...
@@ -43,4 +35,80 @@ class PipelinesFinder
def
tags
project
.
repository
.
tag_names
end
def
by_scope
(
items
)
case
params
[
:scope
]
when
'running'
items
.
running
when
'pending'
items
.
pending
when
'finished'
items
.
finished
when
'branches'
from_ids
(
ids_for_ref
(
branches
))
when
'tags'
from_ids
(
ids_for_ref
(
tags
))
else
items
end
end
def
by_status
(
items
)
case
params
[
:status
]
when
'running'
items
.
running
when
'pending'
items
.
pending
when
'success'
items
.
success
when
'failed'
items
.
failed
when
'canceled'
items
.
canceled
when
'skipped'
items
.
skipped
else
items
end
end
def
by_ref
(
items
)
if
params
[
:ref
].
present?
items
.
where
(
ref:
params
[
:ref
])
else
items
end
end
def
by_user
(
items
)
if
params
[
:user_id
].
present?
items
.
where
(
user_id:
params
[
:user_id
])
else
items
end
end
def
by_duration
(
items
)
if
params
[
:duration
].
present?
items
.
where
(
"duration > ?"
,
params
[
:duration
])
else
items
end
end
def
by_yaml_error
(
items
)
if
params
[
:yaml_error
].
present?
&&
params
[
:yaml_error
]
items
.
where
(
"yaml_errors IS NOT NULL"
)
else
items
end
end
def
order_and_sort
(
items
)
if
params
[
:order_by
].
present?
&&
params
[
:sort
].
present?
items
.
order
(
"
#{
params
[
:order_by
]
}
#{
params
[
:sort
]
}
"
)
else
items
.
order
(
id: :desc
)
end
end
end
lib/api/pipelines.rb
浏览文件 @
e9d94451
...
...
@@ -16,11 +16,21 @@ module API
use
:pagination
optional
:scope
,
type:
String
,
values:
%w(running branches tags)
,
desc:
'Either running, branches, or tags'
optional
:status
,
type:
String
,
values:
[
'running'
,
'pending'
,
'success'
,
'failed'
,
'canceled'
,
'skipped'
],
desc:
'Pipeline Status'
optional
:ref
,
type:
String
,
desc:
'Pipeline Ref'
optional
:duration
,
type:
Integer
,
desc:
'Greater than the specified duration'
optional
:yaml_error
,
type:
Boolean
,
desc:
'If true, returns only yaml error pipelines.'
optional
:user_id
,
type:
String
,
desc:
'User who executed pipelines'
optional
:order_by
,
type:
String
,
values:
[
'id'
,
'status'
,
'ref'
,
'user_id'
,
'started_at'
,
'finished_at'
,
'created_at'
,
'updated_at'
],
default:
'id'
,
desc:
'Return issues ordered by `created_at` or `updated_at` fields.'
optional
:sort
,
type:
String
,
values:
[
'asc'
,
'desc'
],
default:
'desc'
,
desc:
'Return pipelines sorted in `asc` or `desc` order.'
end
get
':id/pipelines'
do
authorize!
:read_pipeline
,
user_project
pipelines
=
PipelinesFinder
.
new
(
user_project
).
execute
(
scope:
params
[
:scope
])
pipelines
=
PipelinesFinder
.
new
(
user_project
,
params
).
execute
(
scope:
params
[
:scope
])
present
paginate
(
pipelines
),
with:
Entities
::
PipelineBasic
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录