Update to VS Code 1.52.1
This commit is contained in:
@ -9,6 +9,7 @@ import { API as GitAPI, Repository } from './typings/git';
|
||||
import { getOctokit } from './auth';
|
||||
import { TextEncoder } from 'util';
|
||||
import { basename } from 'path';
|
||||
import { Octokit } from '@octokit/rest';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
@ -57,9 +58,18 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
|
||||
quickpick.show();
|
||||
quickpick.busy = true;
|
||||
|
||||
const octokit = await getOctokit();
|
||||
const user = await octokit.users.getAuthenticated({});
|
||||
const owner = user.data.login;
|
||||
let owner: string;
|
||||
let octokit: Octokit;
|
||||
try {
|
||||
octokit = await getOctokit();
|
||||
const user = await octokit.users.getAuthenticated({});
|
||||
owner = user.data.login;
|
||||
} catch (e) {
|
||||
// User has cancelled sign in
|
||||
quickpick.dispose();
|
||||
return;
|
||||
}
|
||||
|
||||
quickpick.busy = false;
|
||||
|
||||
let repo: string | undefined;
|
||||
@ -139,7 +149,7 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
|
||||
new Promise<undefined>(c => quickpick.onDidHide(() => c(undefined)))
|
||||
]);
|
||||
|
||||
if (!result) {
|
||||
if (!result || result.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -192,9 +202,9 @@ export async function publishRepository(gitAPI: GitAPI, repository?: Repository)
|
||||
}
|
||||
|
||||
const openInGitHub = 'Open In GitHub';
|
||||
const action = await vscode.window.showInformationMessage(`Successfully published the '${owner}/${repo}' repository on GitHub.`, openInGitHub);
|
||||
|
||||
if (action === openInGitHub) {
|
||||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(githubRepository.html_url));
|
||||
}
|
||||
vscode.window.showInformationMessage(`Successfully published the '${owner}/${repo}' repository on GitHub.`, openInGitHub).then(action => {
|
||||
if (action === openInGitHub) {
|
||||
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(githubRepository.html_url));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -40,8 +40,14 @@ async function handlePushError(repository: Repository, remote: Remote, refspec:
|
||||
|
||||
// Issue: what if there's already another `origin` repo?
|
||||
await repository.addRemote('origin', ghRepository.clone_url);
|
||||
await repository.fetch('origin', remoteName);
|
||||
await repository.setBranchUpstream(localName, `origin/${remoteName}`);
|
||||
|
||||
try {
|
||||
await repository.fetch('origin', remoteName);
|
||||
await repository.setBranchUpstream(localName, `origin/${remoteName}`);
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
|
||||
await repository.push('origin', localName, true);
|
||||
|
||||
return [octokit, ghRepository];
|
||||
|
@ -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}`,
|
||||
@ -28,17 +34,30 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
|
||||
|
||||
async getRemoteSources(query?: string): Promise<RemoteSource[]> {
|
||||
const octokit = await getOctokit();
|
||||
const [fromUser, fromQuery] = await Promise.all([
|
||||
|
||||
if (query) {
|
||||
const repository = parse(query);
|
||||
|
||||
if (repository) {
|
||||
const raw = await octokit.repos.get(repository);
|
||||
return [asRemoteSource(raw.data)];
|
||||
}
|
||||
}
|
||||
|
||||
const all = await Promise.all([
|
||||
this.getUserRemoteSources(octokit, query),
|
||||
this.getQueryRemoteSources(octokit, query)
|
||||
]);
|
||||
|
||||
const userRepos = new Set(fromUser.map(r => r.name));
|
||||
const map = new Map<string, RemoteSource>();
|
||||
|
||||
return [
|
||||
...fromUser,
|
||||
...fromQuery.filter(r => !userRepos.has(r.name))
|
||||
];
|
||||
for (const group of all) {
|
||||
for (const remoteSource of group) {
|
||||
map.set(remoteSource.name, remoteSource);
|
||||
}
|
||||
}
|
||||
|
||||
return [...map.values()];
|
||||
}
|
||||
|
||||
private async getUserRemoteSources(octokit: Octokit, query?: string): Promise<RemoteSource[]> {
|
||||
@ -61,6 +80,35 @@ 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: string[] = [];
|
||||
let page = 1;
|
||||
|
||||
while (true) {
|
||||
let res = await octokit.repos.listBranches({ ...repository, per_page: 100, page });
|
||||
|
||||
if (res.data.length === 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
branches.push(...res.data.map(b => b.name));
|
||||
page++;
|
||||
}
|
||||
|
||||
const repo = await octokit.repos.get(repository);
|
||||
const defaultBranch = repo.data.default_branch;
|
||||
|
||||
return branches.sort((a, b) => a === defaultBranch ? -1 : b === defaultBranch ? 1 : 0);
|
||||
}
|
||||
|
||||
publishRepository(repository: Repository): Promise<void> {
|
||||
return publishRepository(this.gitAPI, repository);
|
||||
}
|
||||
|
@ -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>;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user