Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
csdn-workflow
提交
b4754dc2
C
csdn-workflow
项目概览
BaiXuePrincess
/
csdn-workflow
与 Fork 源项目一致
Fork自
gitcode_dev / csdn-workflow
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,体验更适合开发者的 AI 搜索 >>
提交
b4754dc2
编写于
6月 23, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: extract methods for parsing GqlPosition
上级
ca94f7cd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
59 addition
and
8 deletion
+59
-8
src/review/gitlab_comment_thread.ts
src/review/gitlab_comment_thread.ts
+3
-8
src/review/gql_position_parser.test.ts
src/review/gql_position_parser.test.ts
+45
-0
src/review/gql_position_parser.ts
src/review/gql_position_parser.ts
+11
-0
未找到文件。
src/review/gitlab_comment_thread.ts
浏览文件 @
b4754dc2
...
...
@@ -5,6 +5,7 @@ import { GitLabComment } from './gitlab_comment';
import
{
toReviewUri
}
from
'
./review_uri
'
;
import
{
GqlTextDiffDiscussion
}
from
'
../gitlab/graphql/get_discussions
'
;
import
{
GqlNote
,
GqlTextDiffNote
,
GqlTextPosition
}
from
'
../gitlab/graphql/shared
'
;
import
{
commitFromPosition
,
pathFromPosition
}
from
'
./gql_position_parser
'
;
const
firstNoteFrom
=
(
discussion
:
GqlTextDiffDiscussion
):
GqlTextDiffNote
=>
{
const
note
=
discussion
.
notes
.
nodes
[
0
];
...
...
@@ -22,13 +23,6 @@ const commentRangeFromPosition = (position: GqlTextPosition): vscode.Range => {
return
new
vscode
.
Range
(
vsPosition
,
vsPosition
);
};
const
pathAndCommitFromPosition
=
(
position
:
GqlTextPosition
)
=>
{
const
onOldVersion
=
position
.
oldLine
!==
null
;
const
path
=
onOldVersion
?
position
.
oldPath
:
position
.
newPath
;
const
commit
=
onOldVersion
?
position
.
diffRefs
.
baseSha
:
position
.
diffRefs
.
headSha
;
return
{
path
,
commit
};
};
interface
CreateThreadOptions
{
commentController
:
vscode
.
CommentController
;
repositoryRoot
:
string
;
...
...
@@ -141,7 +135,8 @@ export class GitLabCommentThread {
const
{
position
}
=
firstNoteFrom
(
discussion
);
const
vsThread
=
commentController
.
createCommentThread
(
toReviewUri
({
...
pathAndCommitFromPosition
(
position
),
path
:
pathFromPosition
(
position
),
commit
:
commitFromPosition
(
position
),
repositoryRoot
,
projectId
:
mr
.
project_id
,
mrId
:
mr
.
id
,
...
...
src/review/gql_position_parser.test.ts
0 → 100644
浏览文件 @
b4754dc2
import
{
commitFromPosition
,
pathFromPosition
}
from
'
./gql_position_parser
'
;
import
{
noteOnDiff
}
from
'
../../test/integration/fixtures/graphql/discussions.js
'
;
import
{
GqlTextPosition
}
from
'
../gitlab/graphql/shared
'
;
const
{
position
}
=
noteOnDiff
;
const
oldPosition
=
{
...
position
,
oldLine
:
1
,
newLine
:
null
,
oldPath
:
'
oldPath.js
'
,
diffRefs
:
{
...
position
.
diffRefs
,
baseSha
:
'
abcd
'
,
},
}
as
GqlTextPosition
;
const
newPosition
=
{
...
position
,
oldLine
:
null
,
newLine
:
1
,
newPath
:
'
newPath.js
'
,
diffRefs
:
{
...
position
.
diffRefs
,
headSha
:
'
1234
'
,
},
}
as
GqlTextPosition
;
describe
(
'
pathFromPosition
'
,
()
=>
{
it
(
'
returns old path for old position
'
,
()
=>
{
expect
(
pathFromPosition
(
oldPosition
)).
toBe
(
'
oldPath.js
'
);
});
it
(
'
returns new path for new position
'
,
()
=>
{
expect
(
pathFromPosition
(
newPosition
)).
toBe
(
'
newPath.js
'
);
});
});
describe
(
'
commitFromPosition
'
,
()
=>
{
it
(
'
returns baseSha for old position
'
,
()
=>
{
expect
(
commitFromPosition
(
oldPosition
)).
toBe
(
'
abcd
'
);
});
it
(
'
returns headSha for new position
'
,
()
=>
{
expect
(
commitFromPosition
(
newPosition
)).
toBe
(
'
1234
'
);
});
});
src/review/gql_position_parser.ts
0 → 100644
浏览文件 @
b4754dc2
import
{
GqlTextPosition
}
from
'
../gitlab/graphql/shared
'
;
const
isOld
=
(
position
:
GqlTextPosition
)
=>
position
.
oldLine
!==
null
;
export
const
pathFromPosition
=
(
position
:
GqlTextPosition
):
string
=>
{
return
isOld
(
position
)
?
position
.
oldPath
:
position
.
newPath
;
};
export
const
commitFromPosition
=
(
position
:
GqlTextPosition
):
string
=>
{
return
isOld
(
position
)
?
position
.
diffRefs
.
baseSha
:
position
.
diffRefs
.
headSha
;
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录