From 01a9ebf6a531e001fd0b8099b997d482da16cba2 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Tue, 11 May 2021 18:01:27 +0200 Subject: [PATCH] Make integrations take precedence over providers Signed-off-by: Oliver Sand --- .changeset/polite-plants-exercise.md | 22 ++++--------------- .../processors/GithubOrgReaderProcessor.ts | 8 ++++--- .../processors/github/config.test.ts | 10 +++++++++ .../src/ingestion/processors/github/config.ts | 9 ++++++++ 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/.changeset/polite-plants-exercise.md b/.changeset/polite-plants-exercise.md index ac4a8d1403..2cfa38697a 100644 --- a/.changeset/polite-plants-exercise.md +++ b/.changeset/polite-plants-exercise.md @@ -8,21 +8,7 @@ addition to [`catalog.processors.githubOrg.providers`](https://backstage.io/docs The `integrations` package supports authentication with both personal access tokens and GitHub apps. -This deprecates the `catalog.processors.githubOrg.providers` configuration. If -you still have a configuration for providers the processor keeps working, but -consider moving to the [`integrations` configuration](https://backstage.io/docs/integrations/github/locations) -as the providers will be removed in the future. You might need to allow -additional scopes for the credentials. - -If you want to stay with providers for now, this introduces a small breaking -change, previously if you had no provider configured, one for GitHub was automatically added. To keep the behavior, add a -default provider for GitHub: - -```yaml -catalog: - processors: - githubOrg: - providers: - - target: https://github.com - apiBaseUrl: https://api.github.com -``` +This deprecates the `catalog.processors.githubOrg.providers` configuration. +A [`integrations` configuration](https://backstage.io/docs/integrations/github/locations) +for the same host takes precedence over the provider configuration. +You might need to add additional scopes for the credentials. diff --git a/plugins/catalog-backend/src/ingestion/processors/GithubOrgReaderProcessor.ts b/plugins/catalog-backend/src/ingestion/processors/GithubOrgReaderProcessor.ts index 5840daed74..14204adde7 100644 --- a/plugins/catalog-backend/src/ingestion/processors/GithubOrgReaderProcessor.ts +++ b/plugins/catalog-backend/src/ingestion/processors/GithubOrgReaderProcessor.ts @@ -113,10 +113,10 @@ export class GithubOrgReaderProcessor implements CatalogProcessor { } private async createClient(orgUrl: string): Promise { - let client = this.createClientFromProvider(orgUrl); + let client = await this.createClientFromIntegrations(orgUrl); if (!client) { - client = await this.createClientFromIntegrations(orgUrl); + client = await this.createClientFromProvider(orgUrl); } if (!client) { @@ -128,7 +128,9 @@ export class GithubOrgReaderProcessor implements CatalogProcessor { return client; } - private createClientFromProvider(orgUrl: string): GraphQL | undefined { + private async createClientFromProvider( + orgUrl: string, + ): Promise { const provider = this.providers.find(p => orgUrl.startsWith(`${p.target}/`), ); diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts index b39a7a7ff9..14f3caa42c 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.test.ts @@ -27,6 +27,16 @@ describe('config', () => { }); } + it('adds a default GitHub entry when missing', () => { + const output = readGithubConfig(config([])); + expect(output).toEqual([ + { + target: 'https://github.com', + apiBaseUrl: 'https://api.github.com', + }, + ]); + }); + it('injects the correct GitHub API base URL when missing', () => { const output = readGithubConfig( config([{ target: 'https://github.com' }]), diff --git a/plugins/catalog-backend/src/ingestion/processors/github/config.ts b/plugins/catalog-backend/src/ingestion/processors/github/config.ts index 7b16448b9e..88f2f96218 100644 --- a/plugins/catalog-backend/src/ingestion/processors/github/config.ts +++ b/plugins/catalog-backend/src/ingestion/processors/github/config.ts @@ -71,5 +71,14 @@ export function readGithubConfig(config: Config): ProviderConfig[] { providers.push({ target, apiBaseUrl, token }); } + // If no explicit github.com provider was added, put one in the list as + // a convenience + if (!providers.some(p => p.target === 'https://github.com')) { + providers.push({ + target: 'https://github.com', + apiBaseUrl: 'https://api.github.com', + }); + } + return providers; }