Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一杯枸杞茶ya
csdn-workflow
提交
5c4e6138
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,发现更多精彩内容 >>
提交
5c4e6138
编写于
1月 27, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: some self-managed GitLab deployments not handling project URLs
上级
d19fb6a6
变更
9
显示空白变更内容
内联
并排
Showing
9 changed file
with
107 addition
and
65 deletion
+107
-65
.eslintrc.json
.eslintrc.json
+2
-1
src/commands/create_snippet.js
src/commands/create_snippet.js
+1
-1
src/gitlab/gitlab_new_service.ts
src/gitlab/gitlab_new_service.ts
+24
-2
src/gitlab/gitlab_project.ts
src/gitlab/gitlab_project.ts
+35
-0
src/gitlab_service.ts
src/gitlab_service.ts
+20
-29
src/utils/get_rest_id_from_graphql_id.ts
src/utils/get_rest_id_from_graphql_id.ts
+9
-0
test/integration/fixtures/graphql/project.json
test/integration/fixtures/graphql/project.json
+10
-0
test/integration/fixtures/rest/project.json
test/integration/fixtures/rest/project.json
+0
-29
test/integration/test_infrastructure/mock_server.js
test/integration/test_infrastructure/mock_server.js
+6
-3
未找到文件。
.eslintrc.json
浏览文件 @
5c4e6138
...
@@ -38,7 +38,8 @@
...
@@ -38,7 +38,8 @@
"import/no-extraneous-dependencies"
:
[
"import/no-extraneous-dependencies"
:
[
"error"
,
"error"
,
{
"devDependencies"
:
[
"**/*.test.ts"
,
"test/**/*"
]
}
{
"devDependencies"
:
[
"**/*.test.ts"
,
"test/**/*"
]
}
]
],
"no-useless-constructor"
:
"off"
},
},
"settings"
:
{
"settings"
:
{
"import/resolver"
:
{
"import/resolver"
:
{
...
...
src/commands/create_snippet.js
浏览文件 @
5c4e6138
...
@@ -54,7 +54,7 @@ async function uploadSnippet(project, editor, visibility, context) {
...
@@ -54,7 +54,7 @@ async function uploadSnippet(project, editor, visibility, context) {
data
.
content
=
content
;
data
.
content
=
content
;
if
(
project
)
{
if
(
project
)
{
data
.
id
=
project
.
i
d
;
data
.
id
=
project
.
restI
d
;
}
}
const
snippet
=
await
gitLabService
.
createSnippet
(
data
);
const
snippet
=
await
gitLabService
.
createSnippet
(
data
);
...
...
src/gitlab/gitlab_new_service.ts
浏览文件 @
5c4e6138
...
@@ -10,6 +10,8 @@ import { FetchError } from '../errors/fetch_error';
...
@@ -10,6 +10,8 @@ import { FetchError } from '../errors/fetch_error';
import
{
getUserAgentHeader
}
from
'
../utils/get_user_agent_header
'
;
import
{
getUserAgentHeader
}
from
'
../utils/get_user_agent_header
'
;
import
{
getAvatarUrl
}
from
'
../utils/get_avatar_url
'
;
import
{
getAvatarUrl
}
from
'
../utils/get_avatar_url
'
;
import
{
getHttpAgentOptions
}
from
'
../utils/get_http_agent_options
'
;
import
{
getHttpAgentOptions
}
from
'
../utils/get_http_agent_options
'
;
import
{
GitLabProject
,
GqlProject
}
from
'
./gitlab_project
'
;
import
{
getRestIdFromGraphQLId
}
from
'
../utils/get_rest_id_from_graphql_id
'
;
interface
Node
<
T
>
{
interface
Node
<
T
>
{
pageInfo
?:
{
pageInfo
?:
{
...
@@ -124,6 +126,19 @@ const queryGetSnippets = gql`
...
@@ -124,6 +126,19 @@ const queryGetSnippets = gql`
}
}
`
;
`
;
const
queryGetProject
=
gql
`
query GetProject($projectPath: ID!) {
project(fullPath: $projectPath) {
id
name
fullPath
group {
id
}
}
}
`
;
const
positionFragment
=
gql
`
const
positionFragment
=
gql
`
fragment position on Note {
fragment position on Note {
position {
position {
...
@@ -238,6 +253,13 @@ export class GitLabNewService {
...
@@ -238,6 +253,13 @@ export class GitLabNewService {
};
};
}
}
async
getProject
(
projectPath
:
string
):
Promise
<
GitLabProject
|
undefined
>
{
const
result
=
await
this
.
client
.
request
<
GqlProjectResult
<
GqlProject
>>
(
queryGetProject
,
{
projectPath
,
});
return
result
.
project
&&
new
GitLabProject
(
result
.
project
);
}
async
getSnippets
(
projectPath
:
string
):
Promise
<
GqlSnippet
[]
>
{
async
getSnippets
(
projectPath
:
string
):
Promise
<
GqlSnippet
[]
>
{
const
result
=
await
this
.
client
.
request
<
GqlProjectResult
<
GqlSnippetProject
>>
(
const
result
=
await
this
.
client
.
request
<
GqlProjectResult
<
GqlSnippetProject
>>
(
queryGetSnippets
,
queryGetSnippets
,
...
@@ -264,8 +286,8 @@ export class GitLabNewService {
...
@@ -264,8 +286,8 @@ 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 when https://gitlab.com/gitlab-org/gitlab/-/issues/260316 is done
async
getSnippetContent
(
snippet
:
GqlSnippet
,
blob
:
GqlBlob
):
Promise
<
string
>
{
async
getSnippetContent
(
snippet
:
GqlSnippet
,
blob
:
GqlBlob
):
Promise
<
string
>
{
const
projectId
=
snippet
.
projectId
.
replace
(
'
gid://gitlab/Project/
'
,
''
);
const
projectId
=
getRestIdFromGraphQLId
(
snippet
.
projectId
);
const
snippetId
=
snippet
.
id
.
replace
(
'
gid://gitlab/ProjectSnippet/
'
,
''
);
const
snippetId
=
getRestIdFromGraphQLId
(
snippet
.
id
);
const
url
=
`
${
this
.
instanceUrl
}
/api/v4/projects/
${
projectId
}
/snippets/
${
snippetId
}
/files/master/
${
blob
.
path
}
/raw`
;
const
url
=
`
${
this
.
instanceUrl
}
/api/v4/projects/
${
projectId
}
/snippets/
${
snippetId
}
/files/master/
${
blob
.
path
}
/raw`
;
const
result
=
await
crossFetch
(
url
,
this
.
fetchOptions
);
const
result
=
await
crossFetch
(
url
,
this
.
fetchOptions
);
if
(
!
result
.
ok
)
{
if
(
!
result
.
ok
)
{
...
...
src/gitlab/gitlab_project.ts
0 → 100644
浏览文件 @
5c4e6138
import
{
getRestIdFromGraphQLId
}
from
'
../utils/get_rest_id_from_graphql_id
'
;
interface
GqlGroup
{
id
:
string
;
}
export
interface
GqlProject
{
id
:
string
;
name
:
string
;
fullPath
:
string
;
group
?:
GqlGroup
;
}
export
class
GitLabProject
{
constructor
(
private
readonly
gqlProject
:
GqlProject
)
{}
get
gqlId
():
string
{
return
this
.
gqlProject
.
id
;
}
get
restId
():
number
{
return
getRestIdFromGraphQLId
(
this
.
gqlProject
.
id
);
}
get
name
():
string
{
return
this
.
gqlProject
.
name
;
}
get
fullPath
():
string
{
return
this
.
gqlProject
.
fullPath
;
}
get
groupRestId
():
number
|
undefined
{
return
this
.
gqlProject
.
group
&&
getRestIdFromGraphQLId
(
this
.
gqlProject
.
group
.
id
);
}
}
src/gitlab_service.ts
浏览文件 @
5c4e6138
...
@@ -5,7 +5,7 @@ import { tokenService } from './services/token_service';
...
@@ -5,7 +5,7 @@ import { tokenService } from './services/token_service';
import
{
UserFriendlyError
}
from
'
./errors/user_friendly_error
'
;
import
{
UserFriendlyError
}
from
'
./errors/user_friendly_error
'
;
import
{
ApiError
}
from
'
./errors/api_error
'
;
import
{
ApiError
}
from
'
./errors/api_error
'
;
import
{
getCurrentWorkspaceFolder
}
from
'
./services/workspace_service
'
;
import
{
getCurrentWorkspaceFolder
}
from
'
./services/workspace_service
'
;
import
{
createGitService
}
from
'
./service_factory
'
;
import
{
createGit
LabNewService
,
createGit
Service
}
from
'
./service_factory
'
;
import
{
GitRemote
}
from
'
./git/git_remote_parser
'
;
import
{
GitRemote
}
from
'
./git/git_remote_parser
'
;
import
{
handleError
,
logError
}
from
'
./log
'
;
import
{
handleError
,
logError
}
from
'
./log
'
;
import
{
getUserAgentHeader
}
from
'
./utils/get_user_agent_header
'
;
import
{
getUserAgentHeader
}
from
'
./utils/get_user_agent_header
'
;
...
@@ -14,17 +14,7 @@ import { CustomQuery } from './gitlab/custom_query';
...
@@ -14,17 +14,7 @@ import { CustomQuery } from './gitlab/custom_query';
import
{
getAvatarUrl
}
from
'
./utils/get_avatar_url
'
;
import
{
getAvatarUrl
}
from
'
./utils/get_avatar_url
'
;
import
{
getHttpAgentOptions
}
from
'
./utils/get_http_agent_options
'
;
import
{
getHttpAgentOptions
}
from
'
./utils/get_http_agent_options
'
;
import
{
getInstanceUrl
as
getInstanceUrlUtil
}
from
'
./utils/get_instance_url
'
;
import
{
getInstanceUrl
as
getInstanceUrlUtil
}
from
'
./utils/get_instance_url
'
;
import
{
GitLabProject
}
from
'
./gitlab/gitlab_project
'
;
interface
GitLabProject
{
id
:
number
;
name
:
string
;
namespace
:
{
id
:
number
;
kind
:
string
;
};
// eslint-disable-next-line camelcase
path_with_namespace
:
string
;
}
interface
GitLabPipeline
{
interface
GitLabPipeline
{
id
:
number
;
id
:
number
;
...
@@ -100,14 +90,16 @@ async function fetch(path: string, method = 'GET', data?: Record<string, unknown
...
@@ -100,14 +90,16 @@ async function fetch(path: string, method = 'GET', data?: Record<string, unknown
return
await
request
(
`
${
apiRoot
}${
path
}
`
,
config
);
return
await
request
(
`
${
apiRoot
}${
path
}
`
,
config
);
}
}
async
function
fetchProjectData
(
remote
:
GitRemote
|
null
)
{
async
function
fetchProjectData
(
remote
:
GitRemote
|
null
,
workspaceFolder
:
string
)
{
if
(
remote
)
{
if
(
remote
)
{
if
(
!
(
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
in
projectCache
))
{
if
(
!
(
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
in
projectCache
))
{
const
{
namespace
,
project
}
=
remote
;
const
{
namespace
,
project
}
=
remote
;
const
{
response
}
=
await
fetch
(
`/projects/
${
namespace
.
replace
(
/
\/
/g
,
'
%2F
'
)}
%2F
${
project
}
`
);
const
gitlabNewService
=
await
createGitLabNewService
(
workspaceFolder
);
const
projectData
=
response
;
const
projectData
=
await
gitlabNewService
.
getProject
(
`
${
namespace
}
/
${
project
}
`
);
if
(
projectData
)
{
projectCache
[
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
]
=
projectData
;
projectCache
[
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
]
=
projectData
;
}
}
}
return
projectCache
[
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
]
||
null
;
return
projectCache
[
`
${
remote
.
namespace
}
_
${
remote
.
project
}
`
]
||
null
;
}
}
...
@@ -118,7 +110,7 @@ export async function fetchCurrentProject(workspaceFolder: string): Promise<GitL
...
@@ -118,7 +110,7 @@ export async function fetchCurrentProject(workspaceFolder: string): Promise<GitL
try
{
try
{
const
remote
=
await
createGitService
(
workspaceFolder
).
fetchGitRemote
();
const
remote
=
await
createGitService
(
workspaceFolder
).
fetchGitRemote
();
return
await
fetchProjectData
(
remote
);
return
await
fetchProjectData
(
remote
,
workspaceFolder
);
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
new
ApiError
(
e
,
'
get current project
'
);
throw
new
ApiError
(
e
,
'
get current project
'
);
}
}
...
@@ -137,7 +129,7 @@ export async function fetchCurrentPipelineProject(workspaceFolder: string) {
...
@@ -137,7 +129,7 @@ export async function fetchCurrentPipelineProject(workspaceFolder: string) {
try
{
try
{
const
remote
=
await
createGitService
(
workspaceFolder
).
fetchGitRemotePipeline
();
const
remote
=
await
createGitService
(
workspaceFolder
).
fetchGitRemotePipeline
();
return
await
fetchProjectData
(
remote
);
return
await
fetchProjectData
(
remote
,
workspaceFolder
);
}
catch
(
e
)
{
}
catch
(
e
)
{
logError
(
e
);
logError
(
e
);
return
null
;
return
null
;
...
@@ -195,7 +187,7 @@ export async function fetchLastPipelineForCurrentBranch(workspaceFolder: string)
...
@@ -195,7 +187,7 @@ export async function fetchLastPipelineForCurrentBranch(workspaceFolder: string)
if
(
project
)
{
if
(
project
)
{
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
const
pipelinesRootPath
=
`/projects/
${
project
.
i
d
}
/pipelines`
;
const
pipelinesRootPath
=
`/projects/
${
project
.
restI
d
}
/pipelines`
;
const
{
response
}
=
await
fetch
(
`
${
pipelinesRootPath
}
?ref=
${
branchName
}
`
);
const
{
response
}
=
await
fetch
(
`
${
pipelinesRootPath
}
?ref=
${
branchName
}
`
);
const
pipelines
=
response
;
const
pipelines
=
response
;
...
@@ -246,15 +238,15 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
...
@@ -246,15 +238,15 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
let
path
=
''
;
let
path
=
''
;
if
(
config
.
type
===
'
epics
'
)
{
if
(
config
.
type
===
'
epics
'
)
{
if
(
project
.
namespace
.
kind
===
'
group
'
)
{
if
(
project
.
groupRestId
)
{
path
=
`/groups/
${
project
.
namespace
.
i
d
}
/
${
config
.
type
}
?include_ancestor_groups=true&state=
${
config
.
state
}
`
;
path
=
`/groups/
${
project
.
groupRestI
d
}
/
${
config
.
type
}
?include_ancestor_groups=true&state=
${
config
.
state
}
`
;
}
else
{
}
else
{
return
[];
return
[];
}
}
}
else
{
}
else
{
const
searchKind
=
const
searchKind
=
config
.
type
===
CustomQueryType
.
VULNERABILITY
?
'
vulnerability_findings
'
:
config
.
type
;
config
.
type
===
CustomQueryType
.
VULNERABILITY
?
'
vulnerability_findings
'
:
config
.
type
;
path
=
`/projects/
${
project
.
i
d
}
/
${
searchKind
}
?scope=
${
config
.
scope
}
&state=
${
config
.
state
}
`
;
path
=
`/projects/
${
project
.
restI
d
}
/
${
searchKind
}
?scope=
${
config
.
scope
}
&state=
${
config
.
state
}
`
;
}
}
if
(
config
.
type
===
'
issues
'
)
{
if
(
config
.
type
===
'
issues
'
)
{
if
(
author
)
{
if
(
author
)
{
...
@@ -344,7 +336,7 @@ export async function fetchLastJobsForCurrentBranch(
...
@@ -344,7 +336,7 @@ export async function fetchLastJobsForCurrentBranch(
)
{
)
{
const
project
=
await
fetchCurrentPipelineProject
(
workspaceFolder
);
const
project
=
await
fetchCurrentPipelineProject
(
workspaceFolder
);
if
(
project
)
{
if
(
project
)
{
const
{
response
}
=
await
fetch
(
`/projects/
${
project
.
i
d
}
/pipelines/
${
pipeline
.
id
}
/jobs`
);
const
{
response
}
=
await
fetch
(
`/projects/
${
project
.
restI
d
}
/pipelines/
${
pipeline
.
id
}
/jobs`
);
let
jobs
:
GitLabJob
[]
=
response
;
let
jobs
:
GitLabJob
[]
=
response
;
// Gitlab return multiple jobs if you retry the pipeline we filter to keep only the last
// Gitlab return multiple jobs if you retry the pipeline we filter to keep only the last
...
@@ -368,7 +360,7 @@ export async function fetchOpenMergeRequestForCurrentBranch(workspaceFolder: str
...
@@ -368,7 +360,7 @@ export async function fetchOpenMergeRequestForCurrentBranch(workspaceFolder: str
const
project
=
await
fetchCurrentProjectSwallowError
(
workspaceFolder
);
const
project
=
await
fetchCurrentProjectSwallowError
(
workspaceFolder
);
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
const
path
=
`/projects/
${
project
?.
i
d
}
/merge_requests?state=opened&source_branch=
${
branchName
}
`
;
const
path
=
`/projects/
${
project
?.
restI
d
}
/merge_requests?state=opened&source_branch=
${
branchName
}
`
;
const
{
response
}
=
await
fetch
(
path
);
const
{
response
}
=
await
fetch
(
path
);
const
mrs
=
response
;
const
mrs
=
response
;
...
@@ -389,11 +381,11 @@ export async function handlePipelineAction(action: string, workspaceFolder: stri
...
@@ -389,11 +381,11 @@ export async function handlePipelineAction(action: string, workspaceFolder: stri
const
project
=
await
fetchCurrentProjectSwallowError
(
workspaceFolder
);
const
project
=
await
fetchCurrentProjectSwallowError
(
workspaceFolder
);
if
(
pipeline
&&
project
)
{
if
(
pipeline
&&
project
)
{
let
endpoint
=
`/projects/
${
project
.
i
d
}
/pipelines/
${
pipeline
.
id
}
/
${
action
}
`
;
let
endpoint
=
`/projects/
${
project
.
restI
d
}
/pipelines/
${
pipeline
.
id
}
/
${
action
}
`
;
if
(
action
===
'
create
'
)
{
if
(
action
===
'
create
'
)
{
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
endpoint
=
`/projects/
${
project
.
i
d
}
/pipeline?ref=
${
branchName
}
`
;
endpoint
=
`/projects/
${
project
.
restI
d
}
/pipeline?ref=
${
branchName
}
`
;
}
}
try
{
try
{
...
@@ -415,7 +407,7 @@ export async function fetchMRIssues(mrId: number, workspaceFolder: string) {
...
@@ -415,7 +407,7 @@ export async function fetchMRIssues(mrId: number, workspaceFolder: string) {
if
(
project
)
{
if
(
project
)
{
try
{
try
{
const
{
response
}
=
await
fetch
(
const
{
response
}
=
await
fetch
(
`/projects/
${
project
.
i
d
}
/merge_requests/
${
mrId
}
/closes_issues`
,
`/projects/
${
project
.
restI
d
}
/merge_requests/
${
mrId
}
/closes_issues`
,
);
);
issues
=
response
;
issues
=
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -480,8 +472,7 @@ export async function renderMarkdown(markdown: string, workspaceFolder: string)
...
@@ -480,8 +472,7 @@ export async function renderMarkdown(markdown: string, workspaceFolder: string)
const
project
=
await
fetchCurrentProject
(
workspaceFolder
);
const
project
=
await
fetchCurrentProject
(
workspaceFolder
);
const
{
response
}
=
await
fetch
(
'
/markdown
'
,
'
POST
'
,
{
const
{
response
}
=
await
fetch
(
'
/markdown
'
,
'
POST
'
,
{
text
:
markdown
,
text
:
markdown
,
// eslint-disable-next-line camelcase
project
:
project
?.
fullPath
,
project
:
project
?.
path_with_namespace
,
gfm
:
'
true
'
,
// Needs to be a string for the API
gfm
:
'
true
'
,
// Needs to be a string for the API
});
});
rendered
=
response
;
rendered
=
response
;
...
...
src/utils/get_rest_id_from_graphql_id.ts
0 → 100644
浏览文件 @
5c4e6138
import
*
as
assert
from
'
assert
'
;
// copied from the gitlab-org/gitlab project
// https://gitlab.com/gitlab-org/gitlab/-/blob/a4b939809c68c066e358a280491bf4ec2ff439a2/app/assets/javascripts/graphql_shared/utils.js#L9-10
export
const
getRestIdFromGraphQLId
=
(
gid
:
string
):
number
=>
{
const
result
=
parseInt
(
gid
.
replace
(
/gid:
\/\/
gitlab
\/
.*
\/
/g
,
''
),
10
);
assert
(
result
,
`the gid
${
gid
}
can't be parsed into REST id`
);
return
result
;
};
test/integration/fixtures/graphql/project.json
0 → 100644
浏览文件 @
5c4e6138
{
"project"
:
{
"id"
:
"gid://gitlab/Project/278964"
,
"name"
:
"GitLab"
,
"fullPath"
:
"gitlab-org/gitlab"
,
"group"
:
{
"id"
:
"gid://gitlab/Group/9970"
}
}
}
test/integration/fixtures/rest/project.json
已删除
100644 → 0
浏览文件 @
d19fb6a6
{
"avatar_url"
:
"https://assets.gitlab-static.net/uploads/-/system/project/avatar/278964/logo-extra-whitespace.png"
,
"created_at"
:
"2015-05-20T10:47:11.949Z"
,
"default_branch"
:
"master"
,
"description"
:
"GitLab is an open source end-to-end software development platform with built-in version control, issue tracking, code review, CI/CD, and more. Self-host GitLab on your own servers, in a container, or on a cloud provider."
,
"forks_count"
:
2193
,
"http_url_to_repo"
:
"https://gitlab.com/gitlab-org/gitlab.git"
,
"id"
:
278964
,
"last_activity_at"
:
"2020-07-23T12:59:24.905Z"
,
"name"
:
"GitLab"
,
"name_with_namespace"
:
"GitLab.org / GitLab"
,
"namespace"
:
{
"avatar_url"
:
"/uploads/-/system/group/avatar/9970/logo-extra-whitespace.png"
,
"full_path"
:
"gitlab-org"
,
"id"
:
9970
,
"kind"
:
"group"
,
"name"
:
"GitLab.org"
,
"parent_id"
:
null
,
"path"
:
"gitlab-org"
,
"web_url"
:
"https://gitlab.com/groups/gitlab-org"
},
"path"
:
"gitlab"
,
"path_with_namespace"
:
"gitlab-org/gitlab"
,
"readme_url"
:
"https://gitlab.com/gitlab-org/gitlab/-/blob/master/README.md"
,
"ssh_url_to_repo"
:
"git@gitlab.com:gitlab-org/gitlab.git"
,
"star_count"
:
1974
,
"tag_list"
:
[],
"web_url"
:
"https://gitlab.com/gitlab-org/gitlab"
}
test/integration/test_infrastructure/mock_server.js
浏览文件 @
5c4e6138
const
{
setupServer
}
=
require
(
'
msw/node
'
);
const
{
setupServer
}
=
require
(
'
msw/node
'
);
const
{
rest
}
=
require
(
'
msw
'
);
const
{
rest
,
graphql
}
=
require
(
'
msw
'
);
const
{
API_URL_PREFIX
}
=
require
(
'
./constants
'
);
const
{
API_URL_PREFIX
}
=
require
(
'
./constants
'
);
const
projectResponse
=
require
(
'
../fixtures/
rest
/project.json
'
);
const
projectResponse
=
require
(
'
../fixtures/
graphql
/project.json
'
);
const
versionResponse
=
require
(
'
../fixtures/rest/version.json
'
);
const
versionResponse
=
require
(
'
../fixtures/rest/version.json
'
);
const
createJsonEndpoint
=
(
path
,
response
)
=>
const
createJsonEndpoint
=
(
path
,
response
)
=>
...
@@ -46,7 +46,10 @@ const notFoundByDefault = rest.get(/.*/, (req, res, ctx) => {
...
@@ -46,7 +46,10 @@ const notFoundByDefault = rest.get(/.*/, (req, res, ctx) => {
const
getServer
=
(
handlers
=
[])
=>
{
const
getServer
=
(
handlers
=
[])
=>
{
const
server
=
setupServer
(
const
server
=
setupServer
(
createJsonEndpoint
(
'
/projects/gitlab-org%2Fgitlab
'
,
projectResponse
),
graphql
.
query
(
'
GetProject
'
,
(
req
,
res
,
ctx
)
=>
{
if
(
req
.
variables
.
projectPath
===
'
gitlab-org/gitlab
'
)
return
res
(
ctx
.
data
(
projectResponse
));
return
res
(
ctx
.
data
({
project
:
null
}));
}),
createJsonEndpoint
(
'
/version
'
,
versionResponse
),
createJsonEndpoint
(
'
/version
'
,
versionResponse
),
...
handlers
,
...
handlers
,
notFoundByDefault
,
notFoundByDefault
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录