Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
一杯枸杞茶ya
csdn-workflow
提交
4dbb64d1
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,发现更多精彩内容 >>
提交
4dbb64d1
编写于
4月 22, 2021
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor(gitlab_service): never deduce the workspaceFolder
上级
01deb107
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
30 addition
and
27 deletion
+30
-27
src/ci_config_validator.js
src/ci_config_validator.js
+2
-1
src/commands/create_snippet.js
src/commands/create_snippet.js
+3
-3
src/gitlab_service.ts
src/gitlab_service.ts
+23
-21
src/openers.ts
src/openers.ts
+1
-1
src/status_bar.ts
src/status_bar.ts
+1
-1
未找到文件。
src/ci_config_validator.js
浏览文件 @
4dbb64d1
const
vscode
=
require
(
'
vscode
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
{
getCurrentWorkspaceFolder
}
=
require
(
'
./services/workspace_service
'
);
const
{
showInformationMessage
,
showErrorMessage
}
=
vscode
.
window
;
...
...
@@ -12,7 +13,7 @@ async function validate() {
}
const
content
=
editor
.
document
.
getText
();
const
response
=
await
gitLabService
.
validateCIConfig
(
content
);
const
response
=
await
gitLabService
.
validateCIConfig
(
await
getCurrentWorkspaceFolder
(),
content
);
if
(
!
response
)
{
showInformationMessage
(
'
GitLab Workflow: Failed to validate CI configuration.
'
);
...
...
src/commands/create_snippet.js
浏览文件 @
4dbb64d1
...
...
@@ -30,7 +30,7 @@ const contextOptions = [
},
];
async
function
uploadSnippet
(
project
,
editor
,
visibility
,
context
)
{
async
function
uploadSnippet
(
project
,
editor
,
visibility
,
context
,
workspaceFolder
)
{
let
content
=
''
;
const
fileName
=
editor
.
document
.
fileName
.
split
(
'
/
'
).
reverse
()[
0
];
...
...
@@ -57,7 +57,7 @@ async function uploadSnippet(project, editor, visibility, context) {
data
.
id
=
project
.
restId
;
}
const
snippet
=
await
gitLabService
.
createSnippet
(
data
);
const
snippet
=
await
gitLabService
.
createSnippet
(
workspaceFolder
,
data
);
openers
.
openUrl
(
snippet
.
web_url
);
}
...
...
@@ -90,7 +90,7 @@ async function createSnippet() {
const
context
=
await
vscode
.
window
.
showQuickPick
(
contextOptions
);
if
(
context
)
{
uploadSnippet
(
project
,
editor
,
visibility
.
type
,
context
.
type
);
uploadSnippet
(
project
,
editor
,
visibility
.
type
,
context
.
type
,
workspaceFolder
);
}
}
}
else
{
...
...
src/gitlab_service.ts
浏览文件 @
4dbb64d1
...
...
@@ -4,7 +4,6 @@ import { basename } from 'path';
import
{
tokenService
}
from
'
./services/token_service
'
;
import
{
UserFriendlyError
}
from
'
./errors/user_friendly_error
'
;
import
{
ApiError
}
from
'
./errors/api_error
'
;
import
{
getCurrentWorkspaceFolder
}
from
'
./services/workspace_service
'
;
import
{
createGitLabNewService
,
createGitService
}
from
'
./service_factory
'
;
import
{
GitRemote
}
from
'
./git/git_remote_parser
'
;
import
{
handleError
,
logError
}
from
'
./log
'
;
...
...
@@ -149,9 +148,9 @@ export async function fetchCurrentPipelineProject(workspaceFolder: string) {
}
}
export
async
function
fetchCurrentUser
():
Promise
<
RestUser
>
{
export
async
function
fetchCurrentUser
(
workspaceFolder
:
string
):
Promise
<
RestUser
>
{
try
{
const
{
response
:
user
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
'
/user
'
);
const
{
response
:
user
}
=
await
fetch
(
workspaceFolder
,
'
/user
'
);
if
(
!
user
)
throw
new
Error
(
'
Could not retrieve current user.
'
);
return
user
;
}
catch
(
e
)
{
...
...
@@ -169,10 +168,10 @@ async function fetchFirstUserByUsername(workspaceFolder: string | undefined, use
}
}
export
async
function
fetchVersion
()
{
export
async
function
fetchVersion
(
workspaceFolder
:
string
)
{
try
{
if
(
!
versionCache
)
{
const
{
response
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
'
/version
'
);
const
{
response
}
=
await
fetch
(
workspaceFolder
,
'
/version
'
);
versionCache
=
response
.
version
;
}
}
catch
(
e
)
{
...
...
@@ -232,7 +231,7 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
};
let
issuable
=
null
;
const
version
=
await
fetchVersion
();
const
version
=
await
fetchVersion
(
workspaceFolder
);
const
project
=
await
fetchCurrentProjectSwallowError
(
workspaceFolder
);
if
(
!
version
||
!
project
)
return
[];
...
...
@@ -303,7 +302,7 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
*/
if
(
reviewer
)
{
if
(
reviewer
===
'
<current_user>
'
)
{
const
user
=
await
fetchCurrentUser
();
const
user
=
await
fetchCurrentUser
(
workspaceFolder
);
reviewer
=
user
.
username
;
}
search
.
append
(
'
reviewer_username
'
,
reviewer
);
...
...
@@ -350,10 +349,7 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
// Issue to deprecate this filter: https://gitlab.com/gitlab-org/gitlab-vscode-extension/-/issues/311
if
(
pipelineId
)
{
if
(
pipelineId
===
'
branch
'
)
{
const
workspace
=
await
getCurrentWorkspaceFolder
();
if
(
workspace
)
{
pipelineId
=
(
await
fetchLastPipelineForCurrentBranch
(
workspace
))?.
id
;
}
pipelineId
=
(
await
fetchLastPipelineForCurrentBranch
(
workspaceFolder
))?.
id
;
}
search
.
append
(
'
pipeline_id
'
,
`
${
pipelineId
}
`
);
}
...
...
@@ -385,9 +381,12 @@ export async function fetchIssuables(params: CustomQuery, workspaceFolder: strin
return
issuable
.
map
(
normalizeAvatarUrl
(
await
getInstanceUrl
()));
}
export
async
function
fetchLastJobsForCurrentBranch
(
pipeline
:
RestPipeline
):
Promise
<
RestJob
[]
>
{
export
async
function
fetchLastJobsForCurrentBranch
(
workspaceFolder
:
string
,
pipeline
:
RestPipeline
,
):
Promise
<
RestJob
[]
>
{
const
{
response
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
workspaceFolder
,
`/projects/
${
pipeline
.
project_id
}
/pipelines/
${
pipeline
.
id
}
/jobs`
,
);
let
jobs
:
RestJob
[]
=
response
;
...
...
@@ -423,9 +422,12 @@ export async function fetchOpenMergeRequestForCurrentBranch(
return
null
;
}
export
async
function
fetchLastPipelineForMr
(
mr
:
RestIssuable
):
Promise
<
RestPipeline
|
null
>
{
export
async
function
fetchLastPipelineForMr
(
workspaceFolder
:
string
,
mr
:
RestIssuable
,
):
Promise
<
RestPipeline
|
null
>
{
const
path
=
`/projects/
${
mr
.
project_id
}
/merge_requests/
${
mr
.
iid
}
/pipelines`
;
const
{
response
:
pipelines
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
path
);
const
{
response
:
pipelines
}
=
await
fetch
(
workspaceFolder
,
path
);
return
pipelines
.
length
>
0
?
pipelines
[
0
]
:
null
;
}
...
...
@@ -445,7 +447,7 @@ export async function fetchPipelineAndMrForCurrentBranch(
const
mr
=
await
turnErrorToNull
(
fetchOpenMergeRequestForCurrentBranch
(
workspaceFolder
));
if
(
mr
)
{
const
pipeline
=
await
turnErrorToNull
(
fetchLastPipelineForMr
(
mr
));
const
pipeline
=
await
turnErrorToNull
(
fetchLastPipelineForMr
(
workspaceFolder
,
mr
));
if
(
pipeline
)
return
{
mr
,
pipeline
};
}
const
pipeline
=
await
turnErrorToNull
(
fetchLastPipelineForCurrentBranch
(
workspaceFolder
));
...
...
@@ -504,7 +506,7 @@ export async function fetchMRIssues(
}
// TODO specify the correct interface when we convert `create_snippet.js`
export
async
function
createSnippet
(
data
:
{
id
:
string
})
{
export
async
function
createSnippet
(
workspaceFolder
:
string
,
data
:
{
id
:
string
})
{
let
snippet
;
let
path
=
'
/snippets
'
;
...
...
@@ -513,7 +515,7 @@ export async function createSnippet(data: { id: string }) {
}
try
{
const
{
response
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
path
,
'
POST
'
,
data
);
const
{
response
}
=
await
fetch
(
workspaceFolder
,
path
,
'
POST
'
,
data
);
snippet
=
response
;
}
catch
(
e
)
{
handleError
(
new
UserFriendlyError
(
'
Failed to create your snippet.
'
,
e
));
...
...
@@ -522,11 +524,11 @@ export async function createSnippet(data: { id: string }) {
return
snippet
;
}
export
async
function
validateCIConfig
(
content
:
string
)
{
export
async
function
validateCIConfig
(
workspaceFolder
:
string
,
content
:
string
)
{
let
validCIConfig
=
null
;
try
{
const
{
response
}
=
await
fetch
(
await
getCurrentWorkspaceFolder
()
,
'
/ci/lint
'
,
'
POST
'
,
{
const
{
response
}
=
await
fetch
(
workspaceFolder
,
'
/ci/lint
'
,
'
POST
'
,
{
content
,
});
validCIConfig
=
response
;
...
...
@@ -545,7 +547,7 @@ interface Discussion {
export
async
function
renderMarkdown
(
markdown
:
string
,
workspaceFolder
:
string
)
{
let
rendered
=
{
html
:
markdown
};
const
version
=
await
fetchVersion
();
const
version
=
await
fetchVersion
(
workspaceFolder
);
if
(
!
version
)
{
return
markdown
;
}
...
...
src/openers.ts
浏览文件 @
4dbb64d1
...
...
@@ -27,7 +27,7 @@ export const openUrl = async (url: string): Promise<void> =>
* @param {string} linkTemplate
*/
async
function
getLink
(
linkTemplate
:
string
,
workspaceFolder
:
string
)
{
const
user
=
await
gitLabService
.
fetchCurrentUser
();
const
user
=
await
gitLabService
.
fetchCurrentUser
(
workspaceFolder
);
const
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
assert
(
project
,
'
Failed to fetch project
'
);
...
...
src/status_bar.ts
浏览文件 @
4dbb64d1
...
...
@@ -110,7 +110,7 @@ export class StatusBar {
if
(
status
===
'
running
'
||
status
===
'
failed
'
)
{
try
{
const
jobs
=
await
gitLabService
.
fetchLastJobsForCurrentBranch
(
pipeline
);
const
jobs
=
await
gitLabService
.
fetchLastJobsForCurrentBranch
(
workspaceFolder
,
pipeline
);
if
(
jobs
)
{
statusText
=
createStatusTextFromJobs
(
jobs
,
status
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录