mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-21 17:19:01 +01:00
export to, clone from github
This commit is contained in:
@@ -11,7 +11,7 @@ function sanitizeRepositoryName(value: string): string {
|
||||
return value.trim().replace(/[^a-z0-9_.]/ig, '-');
|
||||
}
|
||||
|
||||
export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI: GitAPI) {
|
||||
export function registerCommands(gitAPI: GitAPI): vscode.Disposable[] {
|
||||
async function publish(): Promise<void> {
|
||||
if (!vscode.workspace.workspaceFolders?.length) {
|
||||
return;
|
||||
@@ -19,15 +19,18 @@ export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI:
|
||||
|
||||
const folder = vscode.workspace.workspaceFolders[0]; // TODO
|
||||
|
||||
const octokit = await getOctokit();
|
||||
const user = await octokit.users.getAuthenticated({});
|
||||
const owner = user.data.login;
|
||||
|
||||
const quickpick = vscode.window.createQuickPick<vscode.QuickPickItem & { repo?: string, auth?: 'https' | 'ssh' }>();
|
||||
quickpick.ignoreFocusOut = true;
|
||||
|
||||
quickpick.placeholder = 'Repository Name';
|
||||
quickpick.value = folder.name;
|
||||
quickpick.show();
|
||||
quickpick.busy = true;
|
||||
|
||||
const octokit = await getOctokit();
|
||||
const user = await octokit.users.getAuthenticated({});
|
||||
const owner = user.data.login;
|
||||
quickpick.busy = false;
|
||||
|
||||
let repo: string | undefined;
|
||||
|
||||
@@ -41,7 +44,6 @@ export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI:
|
||||
}
|
||||
};
|
||||
|
||||
quickpick.value = folder.name;
|
||||
onDidChangeValue();
|
||||
|
||||
while (true) {
|
||||
@@ -108,13 +110,17 @@ export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI:
|
||||
}
|
||||
}
|
||||
|
||||
context.subscriptions.push(vscode.commands.registerCommand('github.publish', async () => {
|
||||
const disposables = [];
|
||||
|
||||
disposables.push(vscode.commands.registerCommand('github.publish', async () => {
|
||||
try {
|
||||
publish();
|
||||
} catch (err) {
|
||||
vscode.window.showErrorMessage(err.message);
|
||||
}
|
||||
}));
|
||||
|
||||
return disposables;
|
||||
}
|
||||
|
||||
function getPick<T extends vscode.QuickPickItem>(quickpick: vscode.QuickPick<T>): Promise<T | undefined> {
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { GithubRemoteSourceProvider } from './remoteSourceProvider';
|
||||
import { GitExtension } from './typings/git';
|
||||
import { registerCommands } from './commands';
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext) {
|
||||
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports;
|
||||
const gitAPI = gitExtension.getAPI(1);
|
||||
|
||||
context.subscriptions.push(...registerCommands(gitAPI));
|
||||
context.subscriptions.push(gitAPI.registerRemoteSourceProvider(new GithubRemoteSourceProvider()));
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ export function getOctokit(): Promise<Octokit> {
|
||||
return new Octokit({
|
||||
request: { agent },
|
||||
userAgent: 'GitHub VSCode',
|
||||
auth() { return `token ${token}`; }
|
||||
auth: `token ${token}`
|
||||
});
|
||||
}).then(null, async err => {
|
||||
_octokit = undefined;
|
||||
|
||||
@@ -40,7 +40,9 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
|
||||
|
||||
private async getUserRemoteSources(octokit: Octokit, query?: string): Promise<RemoteSource[]> {
|
||||
if (!query) {
|
||||
const res = await octokit.repos.list({ sort: 'pushed', per_page: 100 });
|
||||
const user = await octokit.users.getAuthenticated({});
|
||||
const username = user.data.login;
|
||||
const res = await octokit.repos.listForUser({ username, sort: 'updated', per_page: 100 });
|
||||
this.userReposCache = res.data.map(asRemoteSource);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user