use existing parseUrl function to get host and org

Signed-off-by: Brian Fletcher <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2021-08-09 09:20:06 +01:00
parent 6d9698eaa9
commit 5072d05d12
@@ -25,7 +25,6 @@ import { Logger } from 'winston';
import { getOrganizationRepositories } from './github';
import * as results from './results';
import { CatalogProcessor, CatalogProcessorEmit } from './types';
import parseGitUrl from 'git-url-parse';
/**
* Extracts repositories out of a GitHub org.
@@ -65,15 +64,17 @@ export class GithubDiscoveryProcessor implements CatalogProcessor {
);
}
const { org, repoSearchPath, catalogPath, host } = parseUrl(
location.target,
);
// Building the org url here so that the github creds provider doesn't need to know
// about how to handle the wild card which is special for this processor.
const { source, organization } = parseGitUrl(location.target);
const orgUrl = `https://${source}/${organization}`;
const orgUrl = `https://${host}/${org}`;
const { headers } = await GithubCredentialsProvider.create(
gitHubConfig,
).getCredentials({ url: orgUrl });
const { org, repoSearchPath, catalogPath } = parseUrl(location.target);
const client = graphql.defaults({
baseUrl: gitHubConfig.apiBaseUrl,
@@ -119,7 +120,7 @@ export class GithubDiscoveryProcessor implements CatalogProcessor {
export function parseUrl(
urlString: string,
): { org: string; repoSearchPath: RegExp; catalogPath: string } {
): { org: string; repoSearchPath: RegExp; catalogPath: string; host: string } {
const url = new URL(urlString);
const path = url.pathname.substr(1).split('/');
@@ -129,6 +130,7 @@ export function parseUrl(
org: decodeURIComponent(path[0]),
repoSearchPath: escapeRegExp(decodeURIComponent(path[1])),
catalogPath: `/${decodeURIComponent(path.slice(2).join('/'))}`,
host: url.host,
};
}