Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
csdn-workflow
提交
efaf1b74
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 搜索 >>
提交
efaf1b74
编写于
6月 30, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: inserting snippets not working for newly created snippets
上级
192ad5a7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
43 addition
and
6 deletion
+43
-6
src/gitlab/gitlab_new_service.test.ts
src/gitlab/gitlab_new_service.test.ts
+23
-0
src/gitlab/gitlab_new_service.ts
src/gitlab/gitlab_new_service.ts
+9
-2
src/gitlab/graphql/get_snippets.ts
src/gitlab/graphql/get_snippets.ts
+2
-0
test/integration/fixtures/graphql/snippets.json
test/integration/fixtures/graphql/snippets.json
+8
-3
test/integration/insert_snippet.test.js
test/integration/insert_snippet.test.js
+1
-1
未找到文件。
src/gitlab/gitlab_new_service.test.ts
浏览文件 @
efaf1b74
import
{
GraphQLClient
}
from
'
graphql-request
'
;
import
crossFetch
from
'
cross-fetch
'
;
import
{
GitLabNewService
}
from
'
./gitlab_new_service
'
;
import
*
as
snippetsResponse
from
'
../../test/integration/fixtures/graphql/snippets.json
'
;
jest
.
mock
(
'
graphql-request
'
);
jest
.
mock
(
'
../services/token_service
'
);
jest
.
mock
(
'
cross-fetch
'
);
const
crossFetchCallArgument
=
()
=>
(
crossFetch
as
jest
.
Mock
).
mock
.
calls
[
0
][
0
];
describe
(
'
gitlab_new_service
'
,
()
=>
{
describe
(
'
GraphQL client initialization
'
,
()
=>
{
...
...
@@ -17,4 +22,22 @@ describe('gitlab_new_service', () => {
expect
(
GraphQLClient
).
toHaveBeenCalledWith
(
endpointUrl
,
expect
.
anything
());
});
});
describe
(
'
getSnippetContent
'
,
()
=>
{
it
.
each
`
rawPath | branch
${
'
/gitlab-org/gitlab-vscode-extension/-/snippets/111/raw/master/okr.md
'
}
|
${
'
master
'
}
${
'
/gitlab-org/gitlab-vscode-extension/-/snippets/111/raw/main/okr.md
'
}
|
${
'
main
'
}
${
'
/gitlab-org/security/gitlab-vscode-extension/-/snippets/222/raw/customBranch/folder/test1.js
'
}
|
${
'
customBranch
'
}
`
(
'
parses the repository branch from blob rawPath
'
,
async
({
rawPath
,
branch
})
=>
{
(
crossFetch
as
jest
.
Mock
).
mockResolvedValue
({
ok
:
true
,
text
:
()
=>
''
});
const
service
=
new
GitLabNewService
(
'
https://example.com
'
);
const
snippet
=
snippetsResponse
.
project
.
snippets
.
nodes
[
0
];
const
blob
=
snippet
.
blobs
.
nodes
[
0
];
await
service
.
getSnippetContent
(
snippet
,
{
...
blob
,
rawPath
});
expect
(
crossFetchCallArgument
()).
toMatch
(
`/files/
${
branch
}
/`
);
});
});
});
src/gitlab/gitlab_new_service.ts
浏览文件 @
efaf1b74
...
...
@@ -190,11 +190,18 @@ export class GitLabNewService {
}));
}
// TODO change this method to use GraphQL
when https://gitlab.com/gitlab-org/gitlab/-/issues/260316 is done
// TODO change this method to use GraphQL
once the lowest supported GitLab version is 14.1.0
async
getSnippetContent
(
snippet
:
GqlSnippet
,
blob
:
GqlBlob
):
Promise
<
string
>
{
const
getBranch
=
(
rawPath
:
string
)
=>
{
// raw path example: "/gitlab-org/gitlab-vscode-extension/-/snippets/111/raw/master/okr.md"
const
result
=
rawPath
.
match
(
/
\/
-
\/
snippets
\/\d
+
\/
raw
\/([^/]
+
)\/
/
);
assert
(
result
,
`The rawPath is malformed
${
rawPath
}
`
);
return
result
[
1
];
};
const
projectId
=
getRestIdFromGraphQLId
(
snippet
.
projectId
);
const
snippetId
=
getRestIdFromGraphQLId
(
snippet
.
id
);
const
url
=
`
${
this
.
instanceUrl
}
/api/v4/projects/
${
projectId
}
/snippets/
${
snippetId
}
/files/master/
${
blob
.
path
}
/raw`
;
const
branch
=
getBranch
(
blob
.
rawPath
);
const
url
=
`
${
this
.
instanceUrl
}
/api/v4/projects/
${
projectId
}
/snippets/
${
snippetId
}
/files/
${
branch
}
/
${
blob
.
path
}
/raw`
;
const
result
=
await
crossFetch
(
url
,
this
.
fetchOptions
);
if
(
!
result
.
ok
)
{
throw
new
FetchError
(
`Fetching snippet from
${
url
}
failed`
,
result
);
...
...
src/gitlab/graphql/get_snippets.ts
浏览文件 @
efaf1b74
...
...
@@ -14,6 +14,7 @@ export const queryGetSnippets = gql`
nodes {
name
path
rawPath
}
}
}
...
...
@@ -29,6 +30,7 @@ export interface GetSnippetsQueryOptions {
export
interface
GqlBlob
{
name
:
string
;
path
:
string
;
rawPath
:
string
;
}
export
interface
GqlSnippet
{
...
...
test/integration/fixtures/graphql/snippets.json
浏览文件 @
efaf1b74
...
...
@@ -5,30 +5,35 @@
"nodes"
:
[
{
"id"
:
"gid://gitlab/ProjectSnippet/111"
,
"projectId"
:
"gid://gitlab/Project/278964"
,
"title"
:
"Test snippet"
,
"description"
:
"test description"
,
"blobs"
:
{
"nodes"
:
[
{
"name"
:
"test.js"
,
"path"
:
"test.js"
"path"
:
"test.js"
,
"rawPath"
:
"/gitlab-org/gitlab-vscode-extension/-/snippets/111/raw/master/test.js"
}
]
}
},
{
"id"
:
"gid://gitlab/ProjectSnippet/222"
,
"projectId"
:
"gid://gitlab/Project/278964"
,
"title"
:
"Test snippet"
,
"description"
:
"test description"
,
"blobs"
:
{
"nodes"
:
[
{
"name"
:
"test1.js"
,
"path"
:
"test1.js"
"path"
:
"test1.js"
,
"rawPath"
:
"/gitlab-org/gitlab-vscode-extension/-/snippets/222/raw/main/test1.js"
},
{
"name"
:
"test2.js"
,
"path"
:
"test2.js"
"path"
:
"test2.js"
,
"rawPath"
:
"/gitlab-org/gitlab-vscode-extension/-/snippets/222/raw/main/test2.js"
}
]
}
...
...
test/integration/insert_snippet.test.js
浏览文件 @
efaf1b74
...
...
@@ -28,7 +28,7 @@ describe('Insert snippet', async () => {
'
snippet content
'
,
),
createTextEndpoint
(
'
/projects/278964/snippets/222/files/ma
ster
/test2.js/raw
'
,
'
/projects/278964/snippets/222/files/ma
in
/test2.js/raw
'
,
'
second blob content
'
,
),
graphql
.
query
(
'
GetSnippets
'
,
(
req
,
res
,
ctx
)
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录