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 <brian@roadie.io>
This commit is contained in:
Brian Fletcher
2021-08-06 11:03:12 +01:00
parent b0578306b6
commit 6d9698eaa9
2 changed files with 10 additions and 10 deletions
@@ -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);
@@ -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({