Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
0321ca5d
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
0321ca5d
编写于
11月 27, 2020
作者:
J
João Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fixes #106664
上级
8012c255
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
67 addition
and
12 deletion
+67
-12
extensions/git/src/api/api1.ts
extensions/git/src/api/api1.ts
+1
-1
extensions/git/src/api/git.d.ts
extensions/git/src/api/git.d.ts
+1
-0
extensions/git/src/remoteSource.ts
extensions/git/src/remoteSource.ts
+39
-7
extensions/github/src/remoteSourceProvider.ts
extensions/github/src/remoteSourceProvider.ts
+24
-4
extensions/github/src/typings/git.d.ts
extensions/github/src/typings/git.d.ts
+2
-0
未找到文件。
extensions/git/src/api/api1.ts
浏览文件 @
0321ca5d
...
...
@@ -357,7 +357,7 @@ export function registerAPICommands(extension: GitExtensionImpl): Disposable {
return
;
}
return
pickRemoteSource
(
extension
.
model
,
opts
);
return
pickRemoteSource
(
extension
.
model
,
opts
as
any
);
}));
return
Disposable
.
from
(...
disposables
);
...
...
extensions/git/src/api/git.d.ts
浏览文件 @
0321ca5d
...
...
@@ -212,6 +212,7 @@ export interface RemoteSourceProvider {
readonly
icon
?:
string
;
// codicon name
readonly
supportsQuery
?:
boolean
;
getRemoteSources
(
query
?:
string
):
ProviderResult
<
RemoteSource
[]
>
;
getBranches
?(
url
:
string
):
ProviderResult
<
string
[]
>
;
publishRepository
?(
repository
:
Repository
):
Promise
<
void
>
;
}
...
...
extensions/git/src/remoteSource.ts
浏览文件 @
0321ca5d
...
...
@@ -82,9 +82,17 @@ export interface PickRemoteSourceOptions {
readonly
providerLabel
?:
(
provider
:
RemoteSourceProvider
)
=>
string
;
readonly
urlLabel
?:
string
;
readonly
providerName
?:
string
;
readonly
branch
?:
boolean
;
// then result is PickRemoteSourceResult
}
export
async
function
pickRemoteSource
(
model
:
Model
,
options
:
PickRemoteSourceOptions
=
{}):
Promise
<
string
|
undefined
>
{
export
interface
PickRemoteSourceResult
{
readonly
url
:
string
;
readonly
branch
?:
string
;
}
export
async
function
pickRemoteSource
(
model
:
Model
,
options
:
PickRemoteSourceOptions
&
{
branch
?:
false
|
undefined
}):
Promise
<
string
|
undefined
>
;
export
async
function
pickRemoteSource
(
model
:
Model
,
options
:
PickRemoteSourceOptions
&
{
branch
:
true
}):
Promise
<
PickRemoteSourceResult
|
undefined
>
;
export
async
function
pickRemoteSource
(
model
:
Model
,
options
:
PickRemoteSourceOptions
=
{}):
Promise
<
string
|
PickRemoteSourceResult
|
undefined
>
{
const
quickpick
=
window
.
createQuickPick
<
(
QuickPickItem
&
{
provider
?:
RemoteSourceProvider
,
url
?:
string
})
>
();
quickpick
.
ignoreFocusOut
=
true
;
...
...
@@ -93,7 +101,7 @@ export async function pickRemoteSource(model: Model, options: PickRemoteSourceOp
.
filter
(
provider
=>
provider
.
name
===
options
.
providerName
)[
0
];
if
(
provider
)
{
return
await
pickProviderSource
(
provider
);
return
await
pickProviderSource
(
provider
,
options
);
}
}
...
...
@@ -127,24 +135,48 @@ export async function pickRemoteSource(model: Model, options: PickRemoteSourceOp
if
(
result
.
url
)
{
return
result
.
url
;
}
else
if
(
result
.
provider
)
{
return
await
pickProviderSource
(
result
.
provider
);
return
await
pickProviderSource
(
result
.
provider
,
options
);
}
}
return
undefined
;
}
async
function
pickProviderSource
(
provider
:
RemoteSourceProvider
):
Promise
<
string
|
undefined
>
{
async
function
pickProviderSource
(
provider
:
RemoteSourceProvider
,
options
:
PickRemoteSourceOptions
=
{}):
Promise
<
string
|
PickRemoteSourceResult
|
undefined
>
{
const
quickpick
=
new
RemoteSourceProviderQuickPick
(
provider
);
const
remote
=
await
quickpick
.
pick
();
let
url
:
string
|
undefined
;
if
(
remote
)
{
if
(
typeof
remote
.
url
===
'
string
'
)
{
return
remote
.
url
;
url
=
remote
.
url
;
}
else
if
(
remote
.
url
.
length
>
0
)
{
return
await
window
.
showQuickPick
(
remote
.
url
,
{
ignoreFocusOut
:
true
,
placeHolder
:
localize
(
'
pick url
'
,
"
Choose a URL to clone from.
"
)
});
url
=
await
window
.
showQuickPick
(
remote
.
url
,
{
ignoreFocusOut
:
true
,
placeHolder
:
localize
(
'
pick url
'
,
"
Choose a URL to clone from.
"
)
});
}
}
return
undefined
;
if
(
!
url
||
!
options
.
branch
)
{
return
url
;
}
if
(
!
provider
.
getBranches
)
{
return
{
url
};
}
const
branches
=
await
provider
.
getBranches
(
url
);
if
(
!
branches
)
{
return
{
url
};
}
const
branch
=
await
window
.
showQuickPick
(
branches
,
{
placeHolder
:
localize
(
'
branch name
'
,
"
Branch name
"
)
});
if
(
!
branch
)
{
return
{
url
};
}
return
{
url
,
branch
};
}
extensions/github/src/remoteSourceProvider.ts
浏览文件 @
0321ca5d
...
...
@@ -8,6 +8,12 @@ import { getOctokit } from './auth';
import
{
Octokit
}
from
'
@octokit/rest
'
;
import
{
publishRepository
}
from
'
./publish
'
;
function
parse
(
url
:
string
):
{
owner
:
string
,
repo
:
string
}
|
undefined
{
const
match
=
/^https:
\/\/
github
\.
com
\/([^/]
+
)\/([^/]
+
)\.
git/i
.
exec
(
url
)
||
/^git@github
\.
com:
([^/]
+
)\/([^/]
+
)\.
git/i
.
exec
(
url
);
return
(
match
&&
{
owner
:
match
[
1
],
repo
:
match
[
2
]
})
??
undefined
;
}
function
asRemoteSource
(
raw
:
any
):
RemoteSource
{
return
{
name
:
`$(github)
${
raw
.
full_name
}
`
,
...
...
@@ -30,11 +36,10 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
const
octokit
=
await
getOctokit
();
if
(
query
)
{
const
match
=
/^https:
\/\/
github
\.
com
\/([^/]
+
)\/([^/]
+
)\.
git/i
.
exec
(
query
)
||
/^git@github
\.
com:
([^/]
+
)\/([^/]
+
)\.
git/i
.
exec
(
query
);
const
repository
=
parse
(
query
);
if
(
match
)
{
const
raw
=
await
octokit
.
repos
.
get
(
{
owner
:
match
[
1
],
repo
:
match
[
2
]
}
);
if
(
repository
)
{
const
raw
=
await
octokit
.
repos
.
get
(
repository
);
return
[
asRemoteSource
(
raw
.
data
)];
}
}
...
...
@@ -75,6 +80,21 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
return
raw
.
data
.
items
.
map
(
asRemoteSource
);
}
async
getBranches
(
url
:
string
):
Promise
<
string
[]
>
{
const
repository
=
parse
(
url
);
if
(
!
repository
)
{
return
[];
}
const
octokit
=
await
getOctokit
();
const
branches
=
await
octokit
.
repos
.
listBranches
(
repository
);
const
repo
=
await
octokit
.
repos
.
get
(
repository
);
const
defaultBranch
=
repo
.
data
.
default_branch
;
return
branches
.
data
.
map
(
b
=>
b
.
name
).
sort
((
a
,
b
)
=>
a
===
defaultBranch
?
-
1
:
b
===
defaultBranch
?
1
:
0
);
}
publishRepository
(
repository
:
Repository
):
Promise
<
void
>
{
return
publishRepository
(
this
.
gitAPI
,
repository
);
}
...
...
extensions/github/src/typings/git.d.ts
浏览文件 @
0321ca5d
...
...
@@ -130,6 +130,7 @@ export interface CommitOptions {
signoff
?:
boolean
;
signCommit
?:
boolean
;
empty
?:
boolean
;
noVerify
?:
boolean
;
}
export
interface
BranchQuery
{
...
...
@@ -211,6 +212,7 @@ export interface RemoteSourceProvider {
readonly
icon
?:
string
;
// codicon name
readonly
supportsQuery
?:
boolean
;
getRemoteSources
(
query
?:
string
):
ProviderResult
<
RemoteSource
[]
>
;
getBranches
?(
url
:
string
):
ProviderResult
<
string
[]
>
;
publishRepository
?(
repository
:
Repository
):
Promise
<
void
>
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录