Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
356c8b38
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 搜索 >>
提交
356c8b38
编写于
8月 08, 2017
作者:
R
Rémy Coutable
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'project_events_noteable_iid' into 'master'
Expose noteable_iid in Note See merge request !13265
上级
6f555990
7bc04861
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
90 addition
and
3 deletion
+90
-3
changelogs/unreleased/13265-project_events_noteable_iid.yml
changelogs/unreleased/13265-project_events_noteable_iid.yml
+4
-0
doc/api/events.md
doc/api/events.md
+39
-0
doc/api/notes.md
doc/api/notes.md
+6
-3
lib/api/entities.rb
lib/api/entities.rb
+6
-0
spec/requests/api/events_spec.rb
spec/requests/api/events_spec.rb
+35
-0
未找到文件。
changelogs/unreleased/13265-project_events_noteable_iid.yml
0 → 100644
浏览文件 @
356c8b38
---
title
:
Expose noteable_iid in Note
merge_request
:
13265
author
:
sue445
doc/api/events.md
浏览文件 @
356c8b38
...
...
@@ -338,6 +338,45 @@ Example response:
"web_url"
:
"https://gitlab.example.com/ted"
},
"author_username"
:
"ted"
},
{
"title"
:
null
,
"project_id"
:
1
,
"action_name"
:
"commented on"
,
"target_id"
:
1312
,
"target_iid"
:
1312
,
"target_type"
:
"Note"
,
"author_id"
:
1
,
"data"
:
null
,
"target_title"
:
null
,
"created_at"
:
"2015-12-04T10:33:58.089Z"
,
"note"
:
{
"id"
:
1312
,
"body"
:
"What an awesome day!"
,
"attachment"
:
null
,
"author"
:
{
"name"
:
"Dmitriy Zaporozhets"
,
"username"
:
"root"
,
"id"
:
1
,
"state"
:
"active"
,
"avatar_url"
:
"http://localhost:3000/uploads/user/avatar/1/fox_avatar.png"
,
"web_url"
:
"http://localhost:3000/root"
},
"created_at"
:
"2015-12-04T10:33:56.698Z"
,
"system"
:
false
,
"noteable_id"
:
377
,
"noteable_type"
:
"Issue"
,
"noteable_iid"
:
377
},
"author"
:
{
"name"
:
"Dmitriy Zaporozhets"
,
"username"
:
"root"
,
"id"
:
1
,
"state"
:
"active"
,
"avatar_url"
:
"http://localhost:3000/uploads/user/avatar/1/fox_avatar.png"
,
"web_url"
:
"http://localhost:3000/root"
},
"author_username"
:
"root"
}
]
```
...
...
doc/api/notes.md
浏览文件 @
356c8b38
...
...
@@ -35,7 +35,8 @@ Parameters:
"updated_at"
:
"2013-10-02T10:22:45Z"
,
"system"
:
true
,
"noteable_id"
:
377
,
"noteable_type"
:
"Issue"
"noteable_type"
:
"Issue"
,
"noteable_iid"
:
377
},
{
"id"
:
305
,
...
...
@@ -53,7 +54,8 @@ Parameters:
"updated_at"
:
"2013-10-02T09:56:03Z"
,
"system"
:
true
,
"noteable_id"
:
121
,
"noteable_type"
:
"Issue"
"noteable_type"
:
"Issue"
,
"noteable_iid"
:
121
}
]
```
...
...
@@ -267,7 +269,8 @@ Parameters:
"updated_at"
:
"2013-10-02T08:57:14Z"
,
"system"
:
false
,
"noteable_id"
:
2
,
"noteable_type"
:
"MergeRequest"
"noteable_type"
:
"MergeRequest"
,
"noteable_iid"
:
2
}
```
...
...
lib/api/entities.rb
浏览文件 @
356c8b38
...
...
@@ -454,6 +454,9 @@ module API
end
class
Note
<
Grape
::
Entity
# Only Issue and MergeRequest have iid
NOTEABLE_TYPES_WITH_IID
=
%w(Issue MergeRequest)
.
freeze
expose
:id
expose
:note
,
as: :body
expose
:attachment_identifier
,
as: :attachment
...
...
@@ -461,6 +464,9 @@ module API
expose
:created_at
,
:updated_at
expose
:system?
,
as: :system
expose
:noteable_id
,
:noteable_type
# Avoid N+1 queries as much as possible
expose
(
:noteable_iid
)
{
|
note
|
note
.
noteable
.
iid
if
NOTEABLE_TYPES_WITH_IID
.
include?
(
note
.
noteable_type
)
}
end
class
AwardEmoji
<
Grape
::
Entity
...
...
spec/requests/api/events_spec.rb
浏览文件 @
356c8b38
...
...
@@ -138,5 +138,40 @@ describe API::Events do
expect
(
response
).
to
have_http_status
(
404
)
end
end
context
'when exists some events'
do
before
do
create_event
(
note1
)
create_event
(
note2
)
create_event
(
merge_request1
)
end
let
(
:note1
)
{
create
(
:note_on_merge_request
,
project:
private_project
,
author:
user
)
}
let
(
:note2
)
{
create
(
:note_on_issue
,
project:
private_project
,
author:
user
)
}
let
(
:merge_request1
)
{
create
(
:merge_request
,
state:
'closed'
,
author:
user
,
assignee:
user
,
source_project:
private_project
,
title:
'Test'
)
}
let
(
:merge_request2
)
{
create
(
:merge_request
,
state:
'closed'
,
author:
user
,
assignee:
user
,
source_project:
private_project
,
title:
'Test'
)
}
it
'avoids N+1 queries'
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
get
api
(
"/projects/
#{
private_project
.
id
}
/events"
,
user
)
end
.
count
create_event
(
merge_request2
)
expect
do
get
api
(
"/projects/
#{
private_project
.
id
}
/events"
,
user
)
end
.
not_to
exceed_query_limit
(
control_count
)
expect
(
response
).
to
have_http_status
(
200
)
expect
(
response
).
to
include_pagination_headers
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
[
0
]).
to
include
(
'target_type'
=>
'MergeRequest'
,
'target_id'
=>
merge_request2
.
id
)
expect
(
json_response
[
1
]).
to
include
(
'target_type'
=>
'MergeRequest'
,
'target_id'
=>
merge_request1
.
id
)
end
def
create_event
(
target
)
create
(
:event
,
project:
private_project
,
author:
user
,
target:
target
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录