Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
de7b8e51
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 搜索 >>
提交
de7b8e51
编写于
8月 17, 2016
作者:
Z
Z.J. van de Weg
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add endpoints for pipelines
上级
ac73de50
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
208 addition
and
18 deletion
+208
-18
CHANGELOG
CHANGELOG
+1
-0
lib/api/api.rb
lib/api/api.rb
+1
-0
lib/api/entities.rb
lib/api/entities.rb
+8
-0
lib/api/pipelines.rb
lib/api/pipelines.rb
+74
-0
spec/factories/ci/pipelines.rb
spec/factories/ci/pipelines.rb
+0
-18
spec/requests/api/pipelines_spec.rb
spec/requests/api/pipelines_spec.rb
+124
-0
未找到文件。
CHANGELOG
浏览文件 @
de7b8e51
...
...
@@ -51,6 +51,7 @@ v 8.11.0 (unreleased)
- Show deployment status on merge requests with external URLs
- Clean up unused routes (Josef Strzibny)
- Fix issue on empty project to allow developers to only push to protected branches if given permission
- API: Add enpoints for pipelines
- Add green outline to New Branch button. !5447 (winniehell)
- Optimize generating of cache keys for issues and notes
- Improve performance of syntax highlighting Markdown code blocks
...
...
lib/api/api.rb
浏览文件 @
de7b8e51
...
...
@@ -56,6 +56,7 @@ module API
mount
::
API
::
Milestones
mount
::
API
::
Namespaces
mount
::
API
::
Notes
mount
::
API
::
Pipelines
mount
::
API
::
ProjectHooks
mount
::
API
::
ProjectSnippets
mount
::
API
::
Projects
...
...
lib/api/entities.rb
浏览文件 @
de7b8e51
...
...
@@ -502,6 +502,14 @@ module API
expose
:key
,
:value
end
class
Pipeline
<
Grape
::
Entity
expose
:status
,
:ref
,
:sha
,
:before_sha
,
:tag
,
:yaml_errors
expose
:user
,
with:
Entities
::
UserBasic
expose
:created_at
,
:updated_at
,
:started_at
,
:finished_at
,
:committed_at
expose
:duration
end
class
Environment
<
Grape
::
Entity
expose
:id
,
:name
,
:external_url
end
...
...
lib/api/pipelines.rb
0 → 100644
浏览文件 @
de7b8e51
module
API
class
Pipelines
<
Grape
::
API
before
{
authenticate!
}
params
do
requires
:id
,
type:
String
,
desc:
'The project ID'
end
resource
:projects
do
desc
'Get all Pipelines of the project'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
optional
:page
,
type:
Integer
,
desc:
'Page number of the current request'
optional
:per_page
,
type:
Integer
,
desc:
'Number of items per page'
end
get
':id/pipelines'
do
authorize!
:read_pipeline
,
user_project
present
paginate
(
user_project
.
pipelines
),
with:
Entities
::
Pipeline
end
desc
'Gets a specific pipeline for the project'
do
detail
'This feature was introduced in GitLab 8.11'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
get
':id/pipelines/:pipeline_id'
do
authorize!
:read_pipeline
,
user_project
present
pipeline
,
with:
Entities
::
Pipeline
end
desc
'Retry failed builds in the pipeline'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
post
':id/pipelines/:pipeline_id/retry'
do
authorize!
:update_pipeline
,
user_project
pipeline
.
retry_failed
(
current_user
)
present
pipeline
,
with:
Entities
::
Pipeline
end
desc
'Cancel all builds in the pipeline'
do
detail
'This feature was introduced in GitLab 8.11.'
success
Entities
::
Pipeline
end
params
do
requires
:pipeline_id
,
type:
Integer
,
desc:
'The pipeline ID'
end
post
':id/pipelines/:pipeline_id/cancel'
do
authorize!
:update_pipeline
,
user_project
pipeline
.
cancel_running
status
200
present
pipeline
.
reload
,
with:
Entities
::
Pipeline
end
end
helpers
do
def
pipeline
@pipeline
||=
user_project
.
pipelines
.
find
(
params
[
:pipeline_id
])
end
end
end
end
spec/factories/ci/pipelines.rb
浏览文件 @
de7b8e51
# == Schema Information
#
# Table name: commits
#
# id :integer not null, primary key
# project_id :integer
# ref :string(255)
# sha :string(255)
# before_sha :string(255)
# push_data :text
# created_at :datetime
# updated_at :datetime
# tag :boolean default(FALSE)
# yaml_errors :text
# committed_at :datetime
# gl_project_id :integer
#
FactoryGirl
.
define
do
factory
:ci_empty_pipeline
,
class:
Ci
::
Pipeline
do
ref
'master'
...
...
spec/requests/api/pipelines_spec.rb
0 → 100644
浏览文件 @
de7b8e51
require
'spec_helper'
describe
API
::
API
,
api:
true
do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let
(
:non_member
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
)
}
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
before
do
project
.
team
<<
[
user
,
:master
]
end
describe
'GET /projects/:id/pipelines '
do
it_behaves_like
'a paginated resources'
do
let
(
:request
)
{
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
user
)
}
end
context
'authorized user'
do
it
'returns project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'sha'
]).
to
match
/\A\h{40}\z/
end
end
context
'unauthorized user'
do
it
'does not return project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'GET /projects/:id/pipelines/:pipeline_id'
do
context
'authorized user'
do
it
'returns project pipelines'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'sha'
]).
to
match
/\A\h{40}\z/
end
it
'returns 404 when it does not exist'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/123456"
,
user
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'unauthorized user'
do
it
'should not return a project pipeline'
do
get
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'POST /projects/:id/pipelines/:pipeline_id/retry'
do
context
'authorized user'
do
let!
(
:pipeline
)
do
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
let!
(
:build
)
{
create
(
:ci_build
,
:failed
,
pipeline:
pipeline
)
}
it
'retries failed builds'
do
expect
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/retry"
,
user
)
end
.
to
change
{
pipeline
.
builds
.
count
}.
from
(
1
).
to
(
2
)
expect
(
response
).
to
have_http_status
(
201
)
end
end
context
'unauthorized user'
do
it
'should not return a project pipeline'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/retry"
,
non_member
)
expect
(
response
).
to
have_http_status
(
404
)
end
end
end
describe
'POST /projects/:id/pipelines/:pipeline_id/cancel'
do
let!
(
:pipeline
)
do
create
(
:ci_empty_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
end
let!
(
:build
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
)
}
context
'authorized user'
do
it
'retries failed builds'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/cancel"
,
user
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'status'
]).
to
eq
(
'canceled'
)
end
end
context
'user without proper access rights'
do
let!
(
:reporter
)
{
create
(
:user
)
}
before
{
project
.
team
<<
[
reporter
,
:reporter
]
}
it
'rejects the action'
do
post
api
(
"/projects/
#{
project
.
id
}
/pipelines/
#{
pipeline
.
id
}
/cancel"
,
reporter
)
expect
(
response
).
to
have_http_status
(
403
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录