Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gitcode_dev
csdn-workflow
提交
bf0773e7
C
csdn-workflow
项目概览
gitcode_dev
/
csdn-workflow
通知
124
Star
11
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
csdn-workflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
bf0773e7
编写于
6月 15, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: prevent duplicate comments and comment controllers
上级
6d8af151
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
54 addition
and
8 deletion
+54
-8
src/data_providers/items/mr_item_model.test.ts
src/data_providers/items/mr_item_model.test.ts
+11
-0
src/data_providers/items/mr_item_model.ts
src/data_providers/items/mr_item_model.ts
+7
-8
src/review/comment_controller_provider.ts
src/review/comment_controller_provider.ts
+35
-0
test/integration/mr_review.test.js
test/integration/mr_review.test.js
+1
-0
未找到文件。
src/data_providers/items/mr_item_model.test.ts
浏览文件 @
bf0773e7
...
...
@@ -87,5 +87,16 @@ describe('MrItemModel', () => {
item
.
dispose
();
expect
(
commentController
.
dispose
).
toHaveBeenCalled
();
});
it
(
'
when we create comment controller for the same MR, we dispose the previously created controller
'
,
async
()
=>
{
await
item
.
getChildren
();
expect
(
commentController
.
dispose
).
not
.
toHaveBeenCalled
();
// simulates another MR item opening the same MR
await
item
.
getChildren
();
expect
(
commentController
.
dispose
).
toHaveBeenCalled
();
});
});
});
src/data_providers/items/mr_item_model.ts
浏览文件 @
bf0773e7
...
...
@@ -8,6 +8,7 @@ import { UserFriendlyError } from '../../errors/user_friendly_error';
import
{
GitLabCommentThread
}
from
'
../../review/gitlab_comment_thread
'
;
import
{
CommentingRangeProvider
}
from
'
../../review/commenting_range_provider
'
;
import
{
WrappedRepository
}
from
'
../../git/wrapped_repository
'
;
import
{
commentControllerProvider
}
from
'
../../review/comment_controller_provider
'
;
const
isTextDiffDiscussion
=
(
discussion
:
GqlDiscussion
):
discussion
is
GqlTextDiffDiscussion
=>
{
const
firstNote
=
discussion
.
notes
.
nodes
[
0
];
...
...
@@ -60,18 +61,16 @@ export class MrItemModel extends ItemModel {
}
private
async
initializeMrDiscussions
(
mrVersion
:
RestMrVersion
):
Promise
<
void
>
{
const
commentController
=
vscode
.
comments
.
createCommentController
(
`gitlab-mr-
${
this
.
mr
.
references
.
full
}
`
,
const
gitlabService
=
this
.
repository
.
getGitLabService
();
const
userCanComment
=
await
gitlabService
.
canUserCommentOnMr
(
this
.
mr
);
const
commentController
=
commentControllerProvider
.
borrowCommentController
(
this
.
mr
.
references
.
full
,
this
.
mr
.
title
,
userCanComment
?
new
CommentingRangeProvider
(
this
.
mr
,
mrVersion
)
:
undefined
,
);
this
.
setDisposableChildren
([
commentController
]);
const
gitlabService
=
this
.
repository
.
getGitLabService
();
if
(
await
gitlabService
.
canUserCommentOnMr
(
this
.
mr
))
{
commentController
.
commentingRangeProvider
=
new
CommentingRangeProvider
(
this
.
mr
,
mrVersion
);
}
const
discussions
=
await
gitlabService
.
getDiscussions
({
issuable
:
this
.
mr
,
});
...
...
src/review/comment_controller_provider.ts
0 → 100644
浏览文件 @
bf0773e7
import
*
as
vscode
from
'
vscode
'
;
export
class
CommentControllerProvider
{
controllers
:
Record
<
string
,
vscode
.
CommentController
|
undefined
>
=
{};
/**
* Creates comment controller and ensures it is the only existing controller for given MR
* This method exists for several reasons:
* - if we open MR multiple times, we want to prevent multiple comments being displayed
* - multiple comment controllers for the same MR make commenting on MR harder
* - we want to make sure that we add commentingRangeProvider correctly
*/
borrowCommentController
(
mrFullReference
:
string
,
title
:
string
,
commentingRangeProvider
?:
vscode
.
CommentingRangeProvider
,
):
vscode
.
CommentController
{
const
existingController
=
this
.
controllers
[
mrFullReference
];
if
(
existingController
)
{
existingController
.
dispose
();
}
const
controller
=
vscode
.
comments
.
createCommentController
(
`gitlab-mr-
${
mrFullReference
}
`
,
title
,
);
// we must assign commentingRangeProvider right after we create the controller
// if there was an `async` call between, VS Code wouldn't show the commenting range
// this bug has been reported https://github.com/microsoft/vscode/issues/126475
controller
.
commentingRangeProvider
=
commentingRangeProvider
;
this
.
controllers
[
mrFullReference
]
=
controller
;
return
controller
;
}
}
export
const
commentControllerProvider
=
new
CommentControllerProvider
();
test/integration/mr_review.test.js
浏览文件 @
bf0773e7
...
...
@@ -124,6 +124,7 @@ describe('MR Review', () => {
thread
=
{
uri
,
range
,
comments
};
return
thread
;
},
dispose
:
()
=>
{},
};
sandbox
.
stub
(
vscode
.
comments
,
'
createCommentController
'
).
returns
(
commentController
);
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录