Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
57d91211
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,发现更多精彩内容 >>
提交
57d91211
编写于
11月 29, 2017
作者:
H
haseeb
提交者:
Sean McGivern
11月 29, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support ordering of project notes in notes api
上级
7bdcd6f3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
156 addition
and
13 deletion
+156
-13
changelogs/unreleased/32057_support_ordering_project_notes_in_notes_api.yml
...sed/32057_support_ordering_project_notes_in_notes_api.yml
+5
-0
doc/api/notes.md
doc/api/notes.md
+21
-12
lib/api/notes.rb
lib/api/notes.rb
+6
-1
spec/requests/api/notes_spec.rb
spec/requests/api/notes_spec.rb
+124
-0
未找到文件。
changelogs/unreleased/32057_support_ordering_project_notes_in_notes_api.yml
0 → 100644
浏览文件 @
57d91211
---
title
:
added support for ordering and sorting in notes api
merge_request
:
15342
author
:
haseebeqx
type
:
added
doc/api/notes.md
浏览文件 @
57d91211
...
...
@@ -10,12 +10,15 @@ Gets a list of all notes for a single issue.
```
GET /projects/:id/issues/:issue_iid/notes
GET /projects/:id/issues/:issue_iid/notes?sort=asc&order_by=updated_at
```
Parameters:
-
`id`
(required) - The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
-
`issue_iid`
(required) - The IID of an issue
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
|
`issue_iid`
| integer | yes | The IID of an issue
|
`sort`
| string | no | Return issue notes sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
`order_by`
| string | no | Return issue notes ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
```
json
[
...
...
@@ -133,12 +136,15 @@ Gets a list of all notes for a single snippet. Snippet notes are comments users
```
GET /projects/:id/snippets/:snippet_id/notes
GET /projects/:id/snippets/:snippet_id/notes?sort=asc&order_by=updated_at
```
Parameters:
-
`id`
(required) - The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
-
`snippet_id`
(required) - The ID of a project snippet
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
|
`snippet_id`
| integer | yes | The ID of a project snippet
|
`sort`
| string | no | Return snippet notes sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
`order_by`
| string | no | Return snippet notes ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
### Get single snippet note
...
...
@@ -231,12 +237,15 @@ Gets a list of all notes for a single merge request.
```
GET /projects/:id/merge_requests/:merge_request_iid/notes
GET /projects/:id/merge_requests/:merge_request_iid/notes?sort=asc&order_by=updated_at
```
Parameters:
-
`id`
(required) - The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
-
`merge_request_iid`
(required) - The IID of a project merge request
| Attribute | Type | Required | Description |
| ------------------- | ---------------- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
`id`
| integer/string | yes | The ID or
[
URL-encoded path of the project
](
README.md#namespaced-path-encoding
)
owned by the authenticated user
|
`merge_request_iid`
| integer | yes | The IID of a project merge request
|
`sort`
| string | no | Return merge request notes sorted in
`asc`
or
`desc`
order. Default is
`desc`
|
`order_by`
| string | no | Return merge request notes ordered by
`created_at`
or
`updated_at`
fields. Default is
`created_at`
### Get single merge request note
...
...
lib/api/notes.rb
浏览文件 @
57d91211
...
...
@@ -18,6 +18,10 @@ module API
end
params
do
requires
:noteable_id
,
type:
Integer
,
desc:
'The ID of the noteable'
optional
:order_by
,
type:
String
,
values:
%w[created_at updated_at]
,
default:
'created_at'
,
desc:
'Return notes ordered by `created_at` or `updated_at` fields.'
optional
:sort
,
type:
String
,
values:
%w[asc desc]
,
default:
'desc'
,
desc:
'Return notes sorted in `asc` or `desc` order.'
use
:pagination
end
get
":id/
#{
noteables_str
}
/:noteable_id/notes"
do
...
...
@@ -29,11 +33,12 @@ module API
# at the DB query level (which we cannot in that case), the current
# page can have less elements than :per_page even if
# there's more than one page.
raw_notes
=
noteable
.
notes
.
with_metadata
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
notes
=
# paginate() only works with a relation. This could lead to a
# mismatch between the pagination headers info and the actual notes
# array returned, but this is really a edge-case.
paginate
(
noteable
.
notes
.
with_metadata
)
paginate
(
raw_notes
)
.
reject
{
|
n
|
n
.
cross_reference_not_visible_for?
(
current_user
)
}
present
notes
,
with:
Entities
::
Note
else
...
...
spec/requests/api/notes_spec.rb
浏览文件 @
57d91211
...
...
@@ -34,6 +34,48 @@ describe API::Notes do
describe
"GET /projects/:id/noteable/:noteable_id/notes"
do
context
"when noteable is an Issue"
do
context
'sorting'
do
before
do
create_list
(
:note
,
3
,
noteable:
issue
,
project:
project
,
author:
user
)
end
it
'sorts by created_at in descending order by default'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
/notes"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
/notes?sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at in descending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
/notes?order_by=updated_at"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at in ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
/notes??order_by=updated_at&sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
it
"returns an array of issue notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/issues/
#{
issue
.
iid
}
/notes"
,
user
)
...
...
@@ -85,6 +127,47 @@ describe API::Notes do
end
context
"when noteable is a Snippet"
do
context
'sorting'
do
before
do
create_list
(
:note
,
3
,
noteable:
snippet
,
project:
project
,
author:
user
)
end
it
'sorts by created_at in descending order by default'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes?sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at in descending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes?order_by=updated_at"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at in ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes??order_by=updated_at&sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
it
"returns an array of snippet notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/snippets/
#{
snippet
.
id
}
/notes"
,
user
)
...
...
@@ -108,6 +191,47 @@ describe API::Notes do
end
context
"when noteable is a Merge Request"
do
context
'sorting'
do
before
do
create_list
(
:note
,
3
,
noteable:
merge_request
,
project:
project
,
author:
user
)
end
it
'sorts by created_at in descending order by default'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/notes"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/notes?sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'created_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
it
'sorts by updated_at in descending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/notes?order_by=updated_at"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
.
reverse
)
end
it
'sorts by updated_at in ascending order when requested'
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/notes??order_by=updated_at&sort=asc"
,
user
)
response_dates
=
json_response
.
map
{
|
noteable
|
noteable
[
'updated_at'
]
}
expect
(
json_response
.
length
).
to
eq
(
4
)
expect
(
response_dates
).
to
eq
(
response_dates
.
sort
)
end
end
it
"returns an array of merge_requests notes"
do
get
api
(
"/projects/
#{
project
.
id
}
/merge_requests/
#{
merge_request
.
iid
}
/notes"
,
user
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录