From 6d9698eaa92c5b5ed9b646cbe5c26e61a3d597e6 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Fri, 6 Aug 2021 11:03:12 +0100 Subject: [PATCH] move special handling for gh disc processor This change moves the special handling for the GitHub Discovery processor from the GitHub credentials provider into the GitHub Discovery logic. Signed-off-by: Brian Fletcher --- .../src/github/GithubCredentialsProvider.ts | 11 ++--------- .../ingestion/processors/GithubDiscoveryProcessor.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/integration/src/github/GithubCredentialsProvider.ts b/packages/integration/src/github/GithubCredentialsProvider.ts index ebd9fce745..fd5d13caa2 100644 --- a/packages/integration/src/github/GithubCredentialsProvider.ts +++ b/packages/integration/src/github/GithubCredentialsProvider.ts @@ -86,11 +86,7 @@ class GithubAppManager { ): Promise<{ accessToken: string }> { const { installationId, suspended } = await this.getInstallationData(owner); if (suspended) { - throw new Error( - `The GitHub application for ${[owner] - .filter(Boolean) - .join('/')} is suspended`, - ); + throw new Error(`The GitHub application for ${owner} is suspended`); } const cacheKey = repo ? `${owner}/${repo}` : owner; @@ -233,10 +229,7 @@ export class GithubCredentialsProvider { const parsed = parseGitUrl(opts.url); const owner = parsed.owner || parsed.name; - let repo = parsed.owner ? parsed.name : undefined; - // the github-discovery plugin passes an • as a repo name. This simply means it wants access to all repos - // that are available to the installation. - repo = repo === '*' ? undefined : repo; + const repo = parsed.owner ? parsed.name : undefined; let type: GithubCredentialType = 'app'; let token = await this.githubAppCredentialsMux.getAppToken(owner, repo); diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts index 2219e02406..e28e56941b 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubDiscoveryProcessor.ts @@ -25,6 +25,7 @@ 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. @@ -63,9 +64,15 @@ export class GithubDiscoveryProcessor implements CatalogProcessor { `There is no GitHub integration that matches ${location.target}. Please add a configuration entry for it under integrations.github`, ); } + + // 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 { headers } = await GithubCredentialsProvider.create( gitHubConfig, - ).getCredentials({ url: location.target }); + ).getCredentials({ url: orgUrl }); const { org, repoSearchPath, catalogPath } = parseUrl(location.target); const client = graphql.defaults({