Co-authored-by: João Moreno <joao.moreno@microsoft.com>
This commit is contained in:
100paperkite 2022-04-25 21:36:56 +09:00 committed by GitHub
parent 68131705d0
commit 931997875e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 4 deletions

View File

@ -8,10 +8,15 @@ import { RemoteSourceProvider, RemoteSource } from './typings/git-base';
import { getOctokit } from './auth';
import { Octokit } from '@octokit/rest';
function parse(url: string): { owner: string; repo: string } | undefined {
function getRepositoryFromUrl(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;
return match ? { owner: match[1], repo: match[2] } : undefined;
}
function getRepositoryFromQuery(query: string): { owner: string; repo: string } | undefined {
const match = /^([^/]+)\/([^/]+)$/i.exec(query);
return match ? { owner: match[1], repo: match[2] } : undefined;
}
function asRemoteSource(raw: any): RemoteSource {
@ -37,7 +42,7 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
const octokit = await getOctokit();
if (query) {
const repository = parse(query);
const repository = getRepositoryFromUrl(query);
if (repository) {
const raw = await octokit.repos.get(repository);
@ -77,6 +82,12 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
return [];
}
const repository = getRepositoryFromQuery(query);
if (repository) {
query = `user:${repository.owner}+${repository.repo}`;
}
query += ` fork:true`;
const raw = await octokit.search.repos({ q: query, sort: 'stars' });
@ -84,7 +95,7 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
}
async getBranches(url: string): Promise<string[]> {
const repository = parse(url);
const repository = getRepositoryFromUrl(url);
if (!repository) {
return [];