Skip to content

Commit b629dba

Browse files
committed
export to, clone from github
1 parent ee4e97f commit b629dba

6 files changed

Lines changed: 27 additions & 16 deletions

File tree

extensions/git/src/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ class RemoteSourceProviderQuickPick {
288288
}
289289
} catch (err) {
290290
this.quickpick.items = [{ label: localize('error', "$(error) Error: {0}", err.message), alwaysShow: true }];
291+
console.error(err);
291292
} finally {
292293
this.quickpick.busy = false;
293294
}

extensions/github/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
"command": "github.publish",
2525
"title": "Publish to GitHub"
2626
}
27+
],
28+
"viewsWelcome": [
29+
{
30+
"view": "scm",
31+
"contents": "%welcome.publishFolder%",
32+
"when": "config.git.enabled && git.state == initialized && workbenchState == folder"
33+
}
2734
]
2835
},
29-
"viewsWelcome": [
30-
{
31-
"view": "scm",
32-
"contents": "%welcome.publishFolder%",
33-
"when": "config.git.enabled && git.state == initialized && workbenchState == folder"
34-
}
35-
],
3636
"scripts": {
3737
"vscode:prepublish": "npm run compile",
3838
"compile": "gulp compile-extension:github",

extensions/github/src/commands.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,26 @@ function sanitizeRepositoryName(value: string): string {
1111
return value.trim().replace(/[^a-z0-9_.]/ig, '-');
1212
}
1313

14-
export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI: GitAPI) {
14+
export function registerCommands(gitAPI: GitAPI): vscode.Disposable[] {
1515
async function publish(): Promise<void> {
1616
if (!vscode.workspace.workspaceFolders?.length) {
1717
return;
1818
}
1919

2020
const folder = vscode.workspace.workspaceFolders[0]; // TODO
2121

22-
const octokit = await getOctokit();
23-
const user = await octokit.users.getAuthenticated({});
24-
const owner = user.data.login;
25-
2622
const quickpick = vscode.window.createQuickPick<vscode.QuickPickItem & { repo?: string, auth?: 'https' | 'ssh' }>();
2723
quickpick.ignoreFocusOut = true;
2824

2925
quickpick.placeholder = 'Repository Name';
26+
quickpick.value = folder.name;
3027
quickpick.show();
28+
quickpick.busy = true;
29+
30+
const octokit = await getOctokit();
31+
const user = await octokit.users.getAuthenticated({});
32+
const owner = user.data.login;
33+
quickpick.busy = false;
3134

3235
let repo: string | undefined;
3336

@@ -41,7 +44,6 @@ export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI:
4144
}
4245
};
4346

44-
quickpick.value = folder.name;
4547
onDidChangeValue();
4648

4749
while (true) {
@@ -108,13 +110,17 @@ export function registerGlobalCommands(context: vscode.ExtensionContext, gitAPI:
108110
}
109111
}
110112

111-
context.subscriptions.push(vscode.commands.registerCommand('github.publish', async () => {
113+
const disposables = [];
114+
115+
disposables.push(vscode.commands.registerCommand('github.publish', async () => {
112116
try {
113117
publish();
114118
} catch (err) {
115119
vscode.window.showErrorMessage(err.message);
116120
}
117121
}));
122+
123+
return disposables;
118124
}
119125

120126
function getPick<T extends vscode.QuickPickItem>(quickpick: vscode.QuickPick<T>): Promise<T | undefined> {

extensions/github/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import * as vscode from 'vscode';
77
import { GithubRemoteSourceProvider } from './remoteSourceProvider';
88
import { GitExtension } from './typings/git';
9+
import { registerCommands } from './commands';
910

1011
export async function activate(context: vscode.ExtensionContext) {
1112
const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git')!.exports;
1213
const gitAPI = gitExtension.getAPI(1);
1314

15+
context.subscriptions.push(...registerCommands(gitAPI));
1416
context.subscriptions.push(gitAPI.registerRemoteSourceProvider(new GithubRemoteSourceProvider()));
1517
}

extensions/github/src/octokit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export function getOctokit(): Promise<Octokit> {
4747
return new Octokit({
4848
request: { agent },
4949
userAgent: 'GitHub VSCode',
50-
auth() { return `token ${token}`; }
50+
auth: `token ${token}`
5151
});
5252
}).then(null, async err => {
5353
_octokit = undefined;

extensions/github/src/remoteSourceProvider.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
4040

4141
private async getUserRemoteSources(octokit: Octokit, query?: string): Promise<RemoteSource[]> {
4242
if (!query) {
43-
const res = await octokit.repos.list({ sort: 'pushed', per_page: 100 });
43+
const user = await octokit.users.getAuthenticated({});
44+
const username = user.data.login;
45+
const res = await octokit.repos.listForUser({ username, sort: 'updated', per_page: 100 });
4446
this.userReposCache = res.data.map(asRemoteSource);
4547
}
4648

0 commit comments

Comments
 (0)