Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一杯枸杞茶ya
csdn-workflow
提交
c34adb9c
C
csdn-workflow
项目概览
一杯枸杞茶ya
/
csdn-workflow
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
csdn-workflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c34adb9c
编写于
4月 21, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: only show commenting ranges if user can comment
上级
c17f1492
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
69 addition
and
8 deletion
+69
-8
src/data_providers/items/mr_item_model.test.ts
src/data_providers/items/mr_item_model.test.ts
+25
-2
src/data_providers/items/mr_item_model.ts
src/data_providers/items/mr_item_model.ts
+6
-5
src/gitlab/gitlab_new_service.ts
src/gitlab/gitlab_new_service.ts
+22
-0
test/integration/fixtures/graphql/mr_permissions.json
test/integration/fixtures/graphql/mr_permissions.json
+9
-0
test/integration/mr_review.test.js
test/integration/mr_review.test.js
+6
-0
test/integration/test_infrastructure/mock_server.js
test/integration/test_infrastructure/mock_server.js
+1
-1
未找到文件。
src/data_providers/items/mr_item_model.test.ts
浏览文件 @
c34adb9c
...
...
@@ -7,6 +7,7 @@ import {
multipleNotes
,
}
from
'
../../../test/integration/fixtures/graphql/discussions.js
'
;
import
{
createGitLabNewService
}
from
'
../../service_factory
'
;
import
{
CommentingRangeProvider
}
from
'
../../review/commenting_range_provider
'
;
jest
.
mock
(
'
../../service_factory
'
);
...
...
@@ -16,6 +17,8 @@ const createGitLabNewServiceMock = createGitLabNewService as jest.Mock;
describe
(
'
MrItemModel
'
,
()
=>
{
let
item
:
MrItemModel
;
let
commentThread
:
vscode
.
CommentThread
;
let
canUserCommentOnMr
=
false
;
let
commentController
:
any
;
const
createCommentThreadMock
=
jest
.
fn
();
...
...
@@ -23,12 +26,14 @@ describe('MrItemModel', () => {
item
=
new
MrItemModel
(
mr
,
workspace
);
commentThread
=
{}
as
vscode
.
CommentThread
;
c
reateCommentControllerMock
.
mockReturnValue
(
{
c
ommentController
=
{
createCommentThread
:
createCommentThreadMock
.
mockReturnValue
(
commentThread
),
});
};
createCommentControllerMock
.
mockReturnValue
(
commentController
);
createGitLabNewServiceMock
.
mockReturnValue
({
getDiscussions
:
jest
.
fn
().
mockResolvedValue
([
discussionOnDiff
,
multipleNotes
]),
getMrDiff
:
jest
.
fn
().
mockResolvedValue
({
diffs
:
[]
}),
canUserCommentOnMr
:
jest
.
fn
(()
=>
canUserCommentOnMr
),
});
});
...
...
@@ -49,4 +54,22 @@ describe('MrItemModel', () => {
expect
(
firstComment
.
mode
).
toBe
(
vscode
.
CommentMode
.
Preview
);
expect
(
firstComment
.
body
).
toMatch
(
noteOnDiffTextSnippet
);
});
describe
(
'
commenting range
'
,
()
=>
{
it
(
'
should not add a commenting range provider if user does not have permission to comment
'
,
async
()
=>
{
canUserCommentOnMr
=
false
;
await
item
.
getChildren
();
expect
(
commentController
.
commentingRangeProvider
).
toBe
(
undefined
);
});
it
(
'
should add a commenting range provider if user has permission to comment
'
,
async
()
=>
{
canUserCommentOnMr
=
true
;
await
item
.
getChildren
();
expect
(
commentController
.
commentingRangeProvider
).
toBeInstanceOf
(
CommentingRangeProvider
);
});
});
});
src/data_providers/items/mr_item_model.ts
浏览文件 @
c34adb9c
...
...
@@ -42,7 +42,7 @@ export class MrItemModel extends ItemModel {
const
gitlabService
=
await
createGitLabNewService
(
this
.
workspace
.
uri
);
const
mrVersion
=
await
gitlabService
.
getMrDiff
(
this
.
mr
);
try
{
await
this
.
get
MrDiscussions
(
mrVersion
);
await
this
.
initialize
MrDiscussions
(
mrVersion
);
}
catch
(
e
)
{
handleError
(
new
UserFriendlyError
(
...
...
@@ -60,16 +60,17 @@ export class MrItemModel extends ItemModel {
return
[
overview
,
...
changedFiles
];
}
private
async
get
MrDiscussions
(
mrVersion
:
RestMrVersion
):
Promise
<
void
>
{
private
async
initialize
MrDiscussions
(
mrVersion
:
RestMrVersion
):
Promise
<
void
>
{
const
commentController
=
vscode
.
comments
.
createCommentController
(
this
.
mr
.
references
.
full
,
this
.
mr
.
title
,
);
commentController
.
commentingRangeProvider
=
new
CommentingRangeProvider
(
this
.
mr
,
mrVersion
);
const
gitlabService
=
await
createGitLabNewService
(
this
.
workspace
.
uri
);
if
(
await
gitlabService
.
canUserCommentOnMr
(
this
.
mr
))
{
commentController
.
commentingRangeProvider
=
new
CommentingRangeProvider
(
this
.
mr
,
mrVersion
);
}
const
discussions
=
await
gitlabService
.
getDiscussions
({
issuable
:
this
.
mr
,
});
...
...
src/gitlab/gitlab_new_service.ts
浏览文件 @
c34adb9c
...
...
@@ -308,6 +308,18 @@ const constructGetDiscussionsQuery = (isMr: boolean) => gql`
}
`
;
const
getMrPermissionsQuery
=
gql
`
query GetMrPermissions($projectPath: ID!, $iid: String!) {
project(fullPath: $projectPath) {
mergeRequest(iid: $iid) {
userPermissions {
createNote
}
}
}
}
`
;
const
discussionSetResolved
=
gql
`
mutation DiscussionToggleResolve($replyId: DiscussionID!, $resolved: Boolean!) {
discussionToggleResolve(input: { id: $replyId, resolve: $resolved }) {
...
...
@@ -521,6 +533,16 @@ export class GitLabNewService {
return
discussions
.
nodes
.
map
(
n
=>
this
.
addHostToUrl
(
n
));
}
async
canUserCommentOnMr
(
issuable
:
RestIssuable
):
Promise
<
boolean
>
{
const
projectPath
=
getProjectPath
(
issuable
);
const
result
=
await
this
.
client
.
request
(
getMrPermissionsQuery
,
{
projectPath
,
iid
:
String
(
issuable
.
iid
),
});
assert
(
result
?.
project
?.
mergeRequest
,
`MR
${
issuable
.
references
.
full
}
was not found.`
);
return
Boolean
(
result
.
project
.
mergeRequest
.
userPermissions
?.
createNote
);
}
async
setResolved
(
replyId
:
string
,
resolved
:
boolean
):
Promise
<
void
>
{
try
{
return
await
this
.
client
.
request
<
void
>
(
discussionSetResolved
,
{
...
...
test/integration/fixtures/graphql/mr_permissions.json
0 → 100644
浏览文件 @
c34adb9c
{
"project"
:
{
"mergeRequest"
:
{
"userPermissions"
:
{
"createNote"
:
true
}
}
}
}
test/integration/mr_review.test.js
浏览文件 @
c34adb9c
...
...
@@ -12,6 +12,7 @@ const versionsResponse = require('./fixtures/rest/versions.json');
const
versionResponse
=
require
(
'
./fixtures/rest/mr_version.json
'
);
const
diffNote
=
require
(
'
./fixtures/rest/diff_note.json
'
);
const
{
projectWithMrDiscussions
,
noteOnDiff
}
=
require
(
'
./fixtures/graphql/discussions
'
);
const
mrPermissionsResponse
=
require
(
'
./fixtures/graphql/mr_permissions.json
'
);
const
{
getServer
,
createJsonEndpoint
,
...
...
@@ -44,6 +45,11 @@ describe('MR Review', () => {
return
res
(
ctx
.
data
(
projectWithMrDiscussions
));
return
res
(
ctx
.
data
({
project
:
null
}));
}),
graphql
.
query
(
'
GetMrPermissions
'
,
(
req
,
res
,
ctx
)
=>
{
if
(
req
.
variables
.
projectPath
===
'
gitlab-org/gitlab
'
&&
req
.
variables
.
iid
===
'
33824
'
)
return
res
(
ctx
.
data
(
mrPermissionsResponse
));
return
res
(
ctx
.
data
({
project
:
null
}));
}),
]);
await
tokenService
.
setToken
(
GITLAB_URL
,
'
abcd-secret
'
);
});
...
...
test/integration/test_infrastructure/mock_server.js
浏览文件 @
c34adb9c
...
...
@@ -67,7 +67,7 @@ const getServer = (handlers = []) => {
...
handlers
,
notFoundByDefault
,
);
server
.
listen
();
server
.
listen
(
{
onUnhandledRequest
:
'
warn
'
}
);
return
server
;
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录