Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
gitcode_dev
csdn-workflow
提交
194be064
C
csdn-workflow
项目概览
gitcode_dev
/
csdn-workflow
通知
125
Star
11
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
10
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
csdn-workflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
10
Issue
10
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
194be064
编写于
10月 13, 2020
作者:
T
Tomas Vik
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: select project dialog gets stuck in a perpetual loop
上级
66a2ec1a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
161 addition
and
51 deletion
+161
-51
.vscode/launch.json
.vscode/launch.json
+1
-0
src/data_providers/current_branch.js
src/data_providers/current_branch.js
+2
-1
src/gitlab_service.js
src/gitlab_service.js
+2
-35
src/openers.js
src/openers.js
+9
-8
src/pipeline_actions_picker.js
src/pipeline_actions_picker.js
+2
-1
src/search_input.js
src/search_input.js
+3
-2
src/services/workspace_service.ts
src/services/workspace_service.ts
+52
-0
src/snippet_input.js
src/snippet_input.js
+2
-1
src/status_bar.js
src/status_bar.js
+3
-3
test/integration/services/workspace_service.test.js
test/integration/services/workspace_service.test.js
+85
-0
未找到文件。
.vscode/launch.json
浏览文件 @
194be064
...
...
@@ -34,6 +34,7 @@
"--extensionTestsPath=${workspaceRoot}/out/test/integration/"
,
"<paste the last line of `npm run create-test-workspace` output here>"
],
"preLaunchTask"
:
"${defaultBuildTask}"
,
"stopOnEntry"
:
false
}
]
...
...
src/data_providers/current_branch.js
浏览文件 @
194be064
...
...
@@ -3,6 +3,7 @@ const moment = require('moment');
const
gitLabService
=
require
(
'
../gitlab_service
'
);
const
{
SidebarTreeItem
}
=
require
(
'
./sidebar_tree_item
'
);
const
ErrorItem
=
require
(
'
./error_item
'
);
const
{
getCurrentWorkspaceFolder
}
=
require
(
'
../services/workspace_service
'
);
class
DataProvider
{
constructor
()
{
...
...
@@ -94,7 +95,7 @@ class DataProvider {
async
getChildren
()
{
try
{
const
workspaceFolder
=
await
g
itLabService
.
getCurren
WorkspaceFolder
();
const
workspaceFolder
=
await
g
etCurrent
WorkspaceFolder
();
this
.
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
await
this
.
fetchPipeline
(
workspaceFolder
);
await
this
.
fetchMR
(
workspaceFolder
);
...
...
src/gitlab_service.js
浏览文件 @
194be064
...
...
@@ -4,8 +4,8 @@ const fs = require('fs');
const
{
GitService
}
=
require
(
'
./git_service
'
);
const
tokenService
=
require
(
'
./token_service_wrapper
'
);
const
statusBar
=
require
(
'
./status_bar
'
);
const
gitlabProjectInput
=
require
(
'
./gitlab_project_input
'
);
const
{
ApiError
,
UserFriendlyError
}
=
require
(
'
./errors
'
);
const
{
getCurrentWorkspaceFolder
}
=
require
(
'
./services/workspace_service
'
);
const
projectCache
=
[];
let
versionCache
=
null
;
...
...
@@ -24,43 +24,12 @@ const createGitService = workspaceFolder => {
});
};
async
function
getCurrentWorkspaceFolder
()
{
const
editor
=
vscode
.
window
.
activeTextEditor
;
if
(
editor
&&
editor
.
document
&&
vscode
.
workspace
.
getWorkspaceFolder
(
editor
.
document
.
uri
)
!==
undefined
)
{
const
workspaceFolder
=
vscode
.
workspace
.
getWorkspaceFolder
(
editor
.
document
.
uri
).
uri
.
fsPath
;
return
workspaceFolder
;
}
if
(
vscode
.
workspace
.
workspaceFolders
&&
vscode
.
workspace
.
workspaceFolders
.
length
===
1
)
{
return
vscode
.
workspace
.
workspaceFolders
[
0
].
uri
.
fsPath
;
}
return
null
;
}
async
function
getCurrentWorkspaceFolderOrSelectOne
()
{
let
workspaceFolder
=
null
;
workspaceFolder
=
await
getCurrentWorkspaceFolder
();
if
(
workspaceFolder
==
null
)
{
workspaceFolder
=
await
gitlabProjectInput
.
show
();
}
return
workspaceFolder
;
}
async
function
fetch
(
path
,
method
=
'
GET
'
,
data
=
null
)
{
const
{
ignoreCertificateErrors
,
ca
,
cert
,
certKey
}
=
vscode
.
workspace
.
getConfiguration
(
'
gitlab
'
,
);
const
instanceUrl
=
await
createGitService
(
await
getCurrentWorkspaceFolder
OrSelectOne
(),
await
getCurrentWorkspaceFolder
(),
).
fetchCurrentInstanceUrl
();
const
{
proxy
}
=
vscode
.
workspace
.
getConfiguration
(
'
http
'
);
const
apiRoot
=
`
${
instanceUrl
}
/api/v4`
;
...
...
@@ -682,8 +651,6 @@ exports.fetchVersion = fetchVersion;
exports
.
fetchDiscussions
=
fetchDiscussions
;
exports
.
renderMarkdown
=
renderMarkdown
;
exports
.
saveNote
=
saveNote
;
exports
.
getCurrentWorkspaceFolderOrSelectOne
=
getCurrentWorkspaceFolderOrSelectOne
;
exports
.
getAllGitlabProjects
=
getAllGitlabProjects
;
exports
.
getCurrenWorkspaceFolder
=
getCurrentWorkspaceFolder
;
exports
.
fetchLabelEvents
=
fetchLabelEvents
;
exports
.
createGitService
=
createGitService
;
src/openers.js
浏览文件 @
194be064
...
...
@@ -2,6 +2,7 @@ const vscode = require('vscode');
const
{
GitService
}
=
require
(
'
./git_service
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
tokenService
=
require
(
'
./token_service_wrapper
'
);
const
{
getCurrentWorkspaceFolderOrSelectOne
}
=
require
(
'
./services/workspace_service
'
);
const
openUrl
=
url
=>
vscode
.
commands
.
executeCommand
(
'
vscode.open
'
,
vscode
.
Uri
.
parse
(
url
));
...
...
@@ -44,12 +45,12 @@ async function openLink(linkTemplate, workspaceFolder) {
}
async
function
showIssues
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
await
openLink
(
'
$projectUrl/issues?assignee_id=$userId
'
,
workspaceFolder
);
}
async
function
showMergeRequests
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
await
openLink
(
'
$projectUrl/merge_requests?assignee_id=$userId
'
,
workspaceFolder
);
}
...
...
@@ -95,7 +96,7 @@ async function copyLinkToActiveFile() {
}
async
function
openCurrentMergeRequest
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
const
mr
=
await
gitLabService
.
fetchOpenMergeRequestForCurrentBranch
(
workspaceFolder
);
if
(
mr
)
{
...
...
@@ -104,12 +105,12 @@ async function openCurrentMergeRequest() {
}
async
function
openCreateNewIssue
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
openLink
(
'
$projectUrl/issues/new
'
,
workspaceFolder
);
}
async
function
openCreateNewMr
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
const
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
const
branchName
=
await
createGitService
(
workspaceFolder
).
fetchTrackingBranchName
();
...
...
@@ -117,7 +118,7 @@ async function openCreateNewMr() {
}
async
function
openProjectPage
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
openLink
(
'
$projectUrl
'
,
workspaceFolder
);
}
...
...
@@ -125,7 +126,7 @@ async function openCurrentPipeline(workspaceFolder) {
if
(
!
workspaceFolder
)
{
// Temporarily disable eslint to be able to start enforcing stricter rules
// eslint-disable-next-line no-param-reassign
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
}
const
project
=
await
gitLabService
.
fetchCurrentPipelineProject
(
workspaceFolder
);
...
...
@@ -141,7 +142,7 @@ async function openCurrentPipeline(workspaceFolder) {
async
function
compareCurrentBranch
()
{
let
project
=
null
;
let
lastCommitId
=
null
;
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
lastCommitId
=
await
createGitService
(
workspaceFolder
).
fetchLastCommitId
();
...
...
src/pipeline_actions_picker.js
浏览文件 @
194be064
const
vscode
=
require
(
'
vscode
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
openers
=
require
(
'
./openers
'
);
const
{
getCurrentWorkspaceFolderOrSelectOne
}
=
require
(
'
./services/workspace_service
'
);
async
function
showPicker
()
{
const
items
=
[
...
...
@@ -22,7 +23,7 @@ async function showPicker() {
},
];
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
const
selected
=
await
vscode
.
window
.
showQuickPick
(
items
);
...
...
src/search_input.js
浏览文件 @
194be064
const
vscode
=
require
(
'
vscode
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
openers
=
require
(
'
./openers
'
);
const
{
getCurrentWorkspaceFolderOrSelectOne
}
=
require
(
'
./services/workspace_service
'
);
const
parseQuery
=
(
query
,
noteableType
)
=>
{
const
params
=
{};
...
...
@@ -94,7 +95,7 @@ async function getSearchInput(description) {
}
async
function
showSearchInputFor
(
noteableType
)
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
const
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
const
query
=
await
getSearchInput
(
'
Search in title or description. (Check extension page for search with filters)
'
,
...
...
@@ -113,7 +114,7 @@ async function showMergeRequestSearchInput() {
}
async
function
showProjectAdvancedSearchInput
()
{
const
workspaceFolder
=
await
g
itLabService
.
g
etCurrentWorkspaceFolderOrSelectOne
();
const
workspaceFolder
=
await
getCurrentWorkspaceFolderOrSelectOne
();
const
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
const
query
=
await
getSearchInput
(
'
Project Advanced Search. (Check extension page for Advanced Search)
'
,
...
...
src/services/workspace_service.ts
0 → 100644
浏览文件 @
194be064
import
*
as
vscode
from
'
vscode
'
;
async
function
getWorkspaceFolderForOpenEditor
():
Promise
<
string
|
undefined
>
{
const
editor
=
vscode
.
window
.
activeTextEditor
;
if
(
!
editor
?.
document
.
uri
)
{
return
undefined
;
}
const
workspaceFolder
=
vscode
.
workspace
.
getWorkspaceFolder
(
editor
.
document
.
uri
);
return
workspaceFolder
?.
uri
.
fsPath
;
}
export
async
function
getCurrentWorkspaceFolder
():
Promise
<
string
|
null
>
{
const
editorFolder
=
await
getWorkspaceFolderForOpenEditor
();
if
(
editorFolder
)
{
return
editorFolder
;
}
const
{
workspaceFolders
}
=
vscode
.
workspace
;
if
(
workspaceFolders
&&
workspaceFolders
.
length
===
1
)
{
return
workspaceFolders
[
0
].
uri
.
fsPath
;
}
return
null
;
}
export
async
function
getCurrentWorkspaceFolderOrSelectOne
():
Promise
<
string
|
null
>
{
const
editorFolder
=
await
getWorkspaceFolderForOpenEditor
();
if
(
editorFolder
)
{
return
editorFolder
;
}
const
{
workspaceFolders
}
=
vscode
.
workspace
;
if
(
!
workspaceFolders
||
workspaceFolders
.
length
===
0
)
{
return
null
;
}
if
(
workspaceFolders
.
length
===
1
)
{
return
workspaceFolders
[
0
].
uri
.
fsPath
;
}
const
workspaceFolderOptions
=
workspaceFolders
.
map
(
folder
=>
({
label
:
folder
.
name
,
uri
:
folder
.
uri
.
fsPath
,
}));
const
selectedFolder
=
await
vscode
.
window
.
showQuickPick
(
workspaceFolderOptions
,
{
placeHolder
:
'
Select a workspace
'
,
});
if
(
selectedFolder
)
{
return
selectedFolder
.
uri
;
}
return
null
;
}
src/snippet_input.js
浏览文件 @
194be064
...
...
@@ -2,6 +2,7 @@ const vscode = require('vscode');
const
openers
=
require
(
'
./openers
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
gitlabProjectInput
=
require
(
'
./gitlab_project_input
'
);
const
{
getCurrentWorkspaceFolder
}
=
require
(
'
./services/workspace_service
'
);
const
visibilityOptions
=
[
{
...
...
@@ -67,7 +68,7 @@ async function showPicker() {
let
project
=
null
;
if
(
editor
)
{
workspaceFolder
=
await
g
itLabService
.
getCurren
WorkspaceFolder
();
workspaceFolder
=
await
g
etCurrent
WorkspaceFolder
();
project
=
await
gitLabService
.
fetchCurrentProjectSwallowError
(
workspaceFolder
);
if
(
project
==
null
)
{
...
...
src/status_bar.js
浏览文件 @
194be064
const
vscode
=
require
(
'
vscode
'
);
const
openers
=
require
(
'
./openers
'
);
const
gitLabService
=
require
(
'
./gitlab_service
'
);
const
{
getCurrentWorkspaceFolder
}
=
require
(
'
./services/workspace_service
'
);
const
{
UserFriendlyError
}
=
require
(
'
./errors
'
);
let
context
=
null
;
...
...
@@ -51,7 +52,7 @@ async function refreshPipeline() {
};
try
{
workspaceFolder
=
await
g
itLabService
.
getCurren
WorkspaceFolder
();
workspaceFolder
=
await
g
etCurrent
WorkspaceFolder
();
project
=
await
gitLabService
.
fetchCurrentPipelineProject
(
workspaceFolder
);
if
(
project
!=
null
)
{
pipeline
=
await
gitLabService
.
fetchLastPipelineForCurrentBranch
(
workspaceFolder
);
...
...
@@ -139,13 +140,12 @@ async function fetchMRIssues(workspaceFolder) {
}
async
function
fetchBranchMR
()
{
const
editor
=
vscode
.
window
.
activeTextEditor
;
let
text
=
'
$(git-pull-request) GitLab: No MR.
'
;
let
workspaceFolder
=
null
;
let
project
=
null
;
try
{
workspaceFolder
=
vscode
.
workspace
.
getWorkspaceFolder
(
editor
.
document
.
uri
).
uri
.
fsPath
;
workspaceFolder
=
await
getCurrentWorkspaceFolder
()
;
project
=
await
gitLabService
.
fetchCurrentProject
(
workspaceFolder
);
if
(
project
!=
null
)
{
mr
=
await
gitLabService
.
fetchOpenMergeRequestForCurrentBranch
(
workspaceFolder
);
...
...
test/integration/services/workspace_service.test.js
0 → 100644
浏览文件 @
194be064
const
assert
=
require
(
'
assert
'
);
const
sinon
=
require
(
'
sinon
'
);
const
vscode
=
require
(
'
vscode
'
);
const
workspaceService
=
require
(
'
../../../src/services/workspace_service
'
);
describe
(
'
workspace_service
'
,
()
=>
{
const
sandbox
=
sinon
.
createSandbox
();
describe
(
'
one workspace, no open files
'
,
()
=>
{
it
(
'
getCurrentWorkspaceFolder returns workspace folder
'
,
async
()
=>
{
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolder
();
assert
.
strictEqual
(
result
,
vscode
.
workspace
.
workspaceFolders
[
0
].
uri
.
fsPath
);
});
it
(
'
getCurrentWorkspaceFolderOrSelectOne returns workspace folder
'
,
async
()
=>
{
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolderOrSelectOne
();
assert
.
strictEqual
(
result
,
vscode
.
workspace
.
workspaceFolders
[
0
].
uri
.
fsPath
);
});
});
describe
(
'
multiple workspaces
'
,
()
=>
{
const
fakeFolders
=
[
{
name
:
'
workspace 1
'
,
uri
:
{
fsPath
:
'
/ws1
'
},
},
{
name
:
'
workspace 2
'
,
uri
:
{
fsPath
:
'
/ws2
'
},
},
];
let
originalWorkspace
;
before
(()
=>
{
[
originalWorkspace
]
=
vscode
.
workspace
.
workspaceFolders
;
sandbox
.
stub
(
vscode
.
workspace
,
'
workspaceFolders
'
).
get
(()
=>
fakeFolders
);
});
after
(()
=>
{
sandbox
.
restore
();
});
it
(
'
getCurrentWorkspaceFolder returns null
'
,
async
()
=>
{
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolder
();
assert
.
strictEqual
(
result
,
null
);
});
it
(
'
getCurrentWorkspaceFolderOrSelectOne lets user select a workspace
'
,
async
()
=>
{
// simulating user selecting second option
sandbox
.
stub
(
vscode
.
window
,
'
showQuickPick
'
).
callsFake
(
async
options
=>
{
return
options
[
1
];
});
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolderOrSelectOne
();
assert
.
strictEqual
(
result
,
'
/ws2
'
);
});
describe
(
'
with open editor
'
,
()
=>
{
let
testFileUri
;
beforeEach
(
async
()
=>
{
testFileUri
=
vscode
.
Uri
.
parse
(
`
${
originalWorkspace
.
uri
.
fsPath
}
/newfile.js`
);
const
createFileEdit
=
new
vscode
.
WorkspaceEdit
();
createFileEdit
.
createFile
(
testFileUri
);
await
vscode
.
workspace
.
applyEdit
(
createFileEdit
);
await
vscode
.
window
.
showTextDocument
(
testFileUri
);
});
afterEach
(
async
()
=>
{
const
edit
=
new
vscode
.
WorkspaceEdit
();
edit
.
deleteFile
(
testFileUri
);
await
vscode
.
workspace
.
applyEdit
(
edit
);
});
it
(
'
getCurrentWorkspaceFolder returns workspace folder
'
,
async
()
=>
{
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolder
();
assert
.
strictEqual
(
result
,
originalWorkspace
.
uri
.
fsPath
);
});
it
(
'
getCurrentWorkspaceFolderOrSelectOne returns workspace folder
'
,
async
()
=>
{
const
result
=
await
workspaceService
.
getCurrentWorkspaceFolderOrSelectOne
();
assert
.
strictEqual
(
result
,
originalWorkspace
.
uri
.
fsPath
);
});
});
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录