Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
61baf352
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,发现更多精彩内容 >>
提交
61baf352
编写于
2月 28, 2017
作者:
M
Mark Fletcher
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable filtering milestones by search criteria in the API
- Also remove a redundant test
上级
7733f285
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
30 addition
and
7 deletion
+30
-7
changelogs/unreleased/28807-search-for-milestone-by-title-in-rest-api.yml
...eased/28807-search-for-milestone-by-title-in-rest-api.yml
+4
-0
doc/api/milestones.md
doc/api/milestones.md
+4
-2
lib/api/helpers.rb
lib/api/helpers.rb
+4
-0
lib/api/milestones.rb
lib/api/milestones.rb
+2
-0
spec/requests/api/milestones_spec.rb
spec/requests/api/milestones_spec.rb
+16
-5
未找到文件。
changelogs/unreleased/28807-search-for-milestone-by-title-in-rest-api.yml
0 → 100644
浏览文件 @
61baf352
---
title
:
Enable filtering milestones by search criteria in the API
merge_request
:
9606
author
:
doc/api/milestones.md
浏览文件 @
61baf352
...
...
@@ -10,6 +10,7 @@ GET /projects/:id/milestones?iid=42
GET /projects/:id/milestones?iid[]=42&iid[]=43
GET /projects/:id/milestones?state=active
GET /projects/:id/milestones?state=closed
GET /projects/:id/milestones?search=version
```
Parameters:
...
...
@@ -19,6 +20,7 @@ Parameters:
|
`id`
| integer | yes | The ID of a project |
|
`iid`
| Array[integer] | optional | Return only the milestone having the given
`iid`
|
|
`state`
| string | optional | Return only
`active`
or
`closed`
milestones
` |
| `
search
` | string | optional | Return only milestones with a title or description matching the provided string |
```bash
curl --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v3/projects/5/milestones
...
...
lib/api/helpers.rb
浏览文件 @
61baf352
...
...
@@ -164,6 +164,10 @@ module API
items
.
where
(
iid:
iid
)
end
def
filter_by_search
(
items
,
text
)
items
.
search
(
text
)
end
# error helpers
def
forbidden!
(
reason
=
nil
)
...
...
lib/api/milestones.rb
浏览文件 @
61baf352
...
...
@@ -31,6 +31,7 @@ module API
optional
:state
,
type:
String
,
values:
%w[active closed all]
,
default:
'all'
,
desc:
'Return "active", "closed", or "all" milestones'
optional
:iid
,
type:
Array
[
Integer
],
desc:
'The IID of the milestone'
optional
:search
,
type:
String
,
desc:
'The search criteria for the title or description of the milestone'
use
:pagination
end
get
":id/milestones"
do
...
...
@@ -39,6 +40,7 @@ module API
milestones
=
user_project
.
milestones
milestones
=
filter_milestones_state
(
milestones
,
params
[
:state
])
milestones
=
filter_by_iid
(
milestones
,
params
[
:iid
])
if
params
[
:iid
].
present?
milestones
=
filter_by_search
(
milestones
,
params
[
:search
])
if
params
[
:search
]
present
paginate
(
milestones
),
with:
Entities
::
Milestone
end
...
...
spec/requests/api/milestones_spec.rb
浏览文件 @
61baf352
...
...
@@ -4,8 +4,8 @@ describe API::Milestones, api: true do
include
ApiHelpers
let
(
:user
)
{
create
(
:user
)
}
let!
(
:project
)
{
create
(
:empty_project
,
namespace:
user
.
namespace
)
}
let!
(
:closed_milestone
)
{
create
(
:closed_milestone
,
project:
project
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
)
}
let!
(
:closed_milestone
)
{
create
(
:closed_milestone
,
project:
project
,
title:
'version1'
,
description:
'closed milestone'
)
}
let!
(
:milestone
)
{
create
(
:milestone
,
project:
project
,
title:
'version2'
,
description:
'open milestone'
)
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
...
...
@@ -60,17 +60,28 @@ describe API::Milestones, api: true do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
iid:
[
milestone
.
iid
,
closed_milestone
.
iid
]
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
milestone
.
title
expect
(
json_response
.
first
[
'id'
]).
to
eq
milestone
.
id
end
it
'returns a project milestone by
iid array
'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
iid:
[
milestone
.
iid
,
closed_milestone
.
iid
]
it
'returns a project milestone by
searching for title
'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
search:
'version2'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
2
)
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
milestone
.
title
expect
(
json_response
.
first
[
'id'
]).
to
eq
milestone
.
id
end
it
'returns a project milestones by searching for description'
do
get
api
(
"/projects/
#{
project
.
id
}
/milestones"
,
user
),
search:
'open'
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
.
size
).
to
eq
(
1
)
expect
(
json_response
.
first
[
'title'
]).
to
eq
milestone
.
title
expect
(
json_response
.
first
[
'id'
]).
to
eq
milestone
.
id
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录