mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 11:38:51 +01:00
fixes #106664
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
2
extensions/github/src/typings/git.d.ts
vendored
2
extensions/github/src/typings/git.d.ts
vendored
@@ -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