From 5072d05d12dcfe21a5392c017a3a1c76cb1c8d90 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Mon, 9 Aug 2021 09:20:06 +0100 Subject: [PATCH] use existing parseUrl function to get host and org Signed-off-by: Brian Fletcher --- .../ingestion/processors/GithubDiscoveryProcessor.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts index e28e56941b..b444c23924 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts @@ -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, }; }