export to, clone from github

This commit is contained in:
João Moreno 2020-05-18 15:51:15 +02:00
parent ee4e97fe6a
commit b629dba454
6 changed files with 27 additions and 16 deletions

View file

@ -288,6 +288,7 @@ class RemoteSourceProviderQuickPick {
}
} catch (err) {
this.quickpick.items = [{ label: localize('error', "$(error) Error: {0}", err.message), alwaysShow: true }];
console.error(err);
} finally {
this.quickpick.busy = false;
}

View file

@ -24,15 +24,15 @@
"command": "github.publish",
"title": "Publish to GitHub"
}
],
"viewsWelcome": [
{
"view": "scm",
"contents": "%welcome.publishFolder%",
"when": "config.git.enabled && git.state == initialized && workbenchState == folder"
}
]
},
"viewsWelcome": [
{
"view": "scm",
"contents": "%welcome.publishFolder%",
"when": "config.git.enabled && git.state == initialized && workbenchState == folder"
}
],
"scripts": {
"vscode:prepublish": "npm run compile",
"compile": "gulp compile-extension:github",

View file

@ -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> {

View file

@ -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()));
}

View file

@ -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;

View file

@ -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);
}