Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
f27e972e
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,发现更多精彩内容 >>
提交
f27e972e
编写于
11月 09, 2016
作者:
R
Robert Schilling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Grapify milestones API
上级
c392b0cc
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
66 addition
and
54 deletion
+66
-54
lib/api/milestones.rb
lib/api/milestones.rb
+57
-54
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+9
-0
未找到文件。
lib/api/milestones.rb
浏览文件 @
f27e972e
...
@@ -11,19 +11,25 @@ module API
...
@@ -11,19 +11,25 @@ module API
else
milestones
else
milestones
end
end
end
end
params
:optional_params
do
optional
:description
,
type:
String
,
desc:
'The description of the milestone'
optional
:due_date
,
type:
String
,
desc:
'The due date of the milestone'
end
end
end
params
do
requires
:id
,
type:
String
,
desc:
'The ID of a project'
end
resource
:projects
do
resource
:projects
do
# Get a list of project milestones
desc
'Get a list of project milestones'
do
#
success
Entities
::
Milestone
# Parameters:
end
# id (required) - The ID of a project
params
do
# state (optional) - Return "active" or "closed" milestones
optional
:state
,
type:
String
,
values:
%w[active closed all]
,
default:
'all'
,
# Example Request:
desc:
'Return "active", "closed", or "all" milestones'
# GET /projects/:id/milestones
optional
:iid
,
type:
Integer
,
desc:
'The IID of the milestone'
# GET /projects/:id/milestones?iid=42
end
# GET /projects/:id/milestones?state=active
# GET /projects/:id/milestones?state=closed
get
":id/milestones"
do
get
":id/milestones"
do
authorize!
:read_milestone
,
user_project
authorize!
:read_milestone
,
user_project
...
@@ -34,34 +40,31 @@ module API
...
@@ -34,34 +40,31 @@ module API
present
paginate
(
milestones
),
with:
Entities
::
Milestone
present
paginate
(
milestones
),
with:
Entities
::
Milestone
end
end
# Get a single project milestone
desc
'Get a single project milestone'
do
#
success
Entities
::
Milestone
# Parameters:
end
# id (required) - The ID of a project
params
do
# milestone_id (required) - The ID of a project milestone
requires
:milestone_id
,
type:
Integer
,
desc:
'The ID of a project milestone'
# Example Request:
end
# GET /projects/:id/milestones/:milestone_id
get
":id/milestones/:milestone_id"
do
get
":id/milestones/:milestone_id"
do
authorize!
:read_milestone
,
user_project
authorize!
:read_milestone
,
user_project
@
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
present
@
milestone
,
with:
Entities
::
Milestone
present
milestone
,
with:
Entities
::
Milestone
end
end
# Create a new project milestone
desc
'Create a new project milestone'
do
#
success
Entities
::
Milestone
# Parameters:
end
# id (required) - The ID of the project
params
do
# title (required) - The title of the milestone
requires
:title
,
type:
String
,
desc:
'The title of the milestone'
# description (optional) - The description of the milestone
use
:optional_params
# due_date (optional) - The due date of the milestone
end
# Example Request:
# POST /projects/:id/milestones
post
":id/milestones"
do
post
":id/milestones"
do
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
required_attributes!
[
:title
]
milestone_params
=
declared
(
params
,
include_parent_namespaces:
false
)
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
]
milestone
=
::
Milestones
::
CreateService
.
new
(
user_project
,
current_user
,
attr
s
).
execute
milestone
=
::
Milestones
::
CreateService
.
new
(
user_project
,
current_user
,
milestone_param
s
).
execute
if
milestone
.
valid?
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
present
milestone
,
with:
Entities
::
Milestone
...
@@ -70,22 +73,23 @@ module API
...
@@ -70,22 +73,23 @@ module API
end
end
end
end
# Update an existing project milestone
desc
'Update an existing project milestone'
do
#
success
Entities
::
Milestone
# Parameters:
end
# id (required) - The ID of a project
params
do
# milestone_id (required) - The ID of a project milestone
requires
:milestone_id
,
type:
Integer
,
desc:
'The ID of a project milestone'
# title (optional) - The title of a milestone
optional
:title
,
type:
String
,
desc:
'The title of the milestone'
# description (optional) - The description of a milestone
optional
:state_event
,
type:
String
,
values:
%w[close activate]
,
# due_date (optional) - The due date of a milestone
desc:
'The state event of the milestone '
# state_event (optional) - The state event of the milestone (close|activate)
use
:optional_params
# Example Request:
at_least_one_of
:title
,
:description
,
:due_date
,
:state_event
# PUT /projects/:id/milestones/:milestone_i
d
en
d
put
":id/milestones/:milestone_id"
do
put
":id/milestones/:milestone_id"
do
authorize!
:admin_milestone
,
user_project
authorize!
:admin_milestone
,
user_project
attrs
=
attributes_for_keys
[
:title
,
:description
,
:due_date
,
:state_event
]
milestone_params
=
declared
(
params
,
include_parent_namespaces:
false
,
include_missing:
false
)
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
milestone
=
::
Milestones
::
UpdateService
.
new
(
user_project
,
current_user
,
attrs
).
execute
(
milestone
)
milestone
=
user_project
.
milestones
.
find
(
milestone_params
.
delete
(
:milestone_id
))
milestone
=
::
Milestones
::
UpdateService
.
new
(
user_project
,
current_user
,
milestone_params
).
execute
(
milestone
)
if
milestone
.
valid?
if
milestone
.
valid?
present
milestone
,
with:
Entities
::
Milestone
present
milestone
,
with:
Entities
::
Milestone
...
@@ -94,21 +98,20 @@ module API
...
@@ -94,21 +98,20 @@ module API
end
end
end
end
# Get all issues for a single project milestone
desc
'Get all issues for a single project milestone'
do
#
success
Entities
::
Issue
# Parameters:
end
# id (required) - The ID of a project
params
do
# milestone_id (required) - The ID of a project milestone
requires
:milestone_id
,
type:
Integer
,
desc:
'The ID of a project milestone'
# Example Request:
end
# GET /projects/:id/milestones/:milestone_id/issues
get
":id/milestones/:milestone_id/issues"
do
get
":id/milestones/:milestone_id/issues"
do
authorize!
:read_milestone
,
user_project
authorize!
:read_milestone
,
user_project
@
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
milestone
=
user_project
.
milestones
.
find
(
params
[
:milestone_id
])
finder_params
=
{
finder_params
=
{
project_id:
user_project
.
id
,
project_id:
user_project
.
id
,
milestone_title:
@
milestone
.
title
milestone_title:
milestone
.
title
}
}
issues
=
IssuesFinder
.
new
(
current_user
,
finder_params
).
execute
issues
=
IssuesFinder
.
new
(
current_user
,
finder_params
).
execute
...
...
spec/requests/api/milestones_spec.rb
浏览文件 @
f27e972e
...
@@ -123,6 +123,15 @@ describe API::API, api: true do
...
@@ -123,6 +123,15 @@ describe API::API, api: true do
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
expect
(
json_response
[
'title'
]).
to
eq
(
'updated title'
)
end
end
it
'removes a due date if nil is passed'
do
milestone
.
update!
(
due_date:
"2016-08-05"
)
put
api
(
"/projects/
#{
project
.
id
}
/milestones/
#{
milestone
.
id
}
"
,
user
),
due_date:
nil
expect
(
response
).
to
have_http_status
(
200
)
expect
(
json_response
[
'due_date'
]).
to
be_nil
end
it
'returns a 404 error if milestone id not found'
do
it
'returns a 404 error if milestone id not found'
do
put
api
(
"/projects/
#{
project
.
id
}
/milestones/1234"
,
user
),
put
api
(
"/projects/
#{
project
.
id
}
/milestones/1234"
,
user
),
title:
'updated title'
title:
'updated title'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录