This commit is contained in:
João Moreno
2020-11-10 16:52:35 +01:00
parent d34ba652f3
commit 3d61a39074
2 changed files with 22 additions and 7 deletions

View File

@@ -28,17 +28,31 @@ export class GithubRemoteSourceProvider implements RemoteSourceProvider {
async getRemoteSources(query?: string): Promise<RemoteSource[]> {
const octokit = await getOctokit();
const [fromUser, fromQuery] = await Promise.all([
if (query) {
const match = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\.git/i.exec(query)
|| /^git@github\.com:([^/]+)\/([^/]+)\.git/i.exec(query);
if (match) {
const raw = await octokit.repos.get({ owner: match[1], repo: match[2] });
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[]> {