From ce82656901817c2072419b8913f03183d1043c08 Mon Sep 17 00:00:00 2001 From: Brian Fletcher Date: Fri, 7 Jan 2022 14:13:23 +0000 Subject: [PATCH] removes some breaking compatability changes Signed-off-by: Brian Fletcher --- .changeset/cold-toes-sniff.md | 2 +- .../src/github/DefaultGithubCredentialsProvider.ts | 6 +++++- plugins/catalog-backend/api-report.md | 2 +- .../ingestion/providers/GitHubOrgEntityProvider.ts | 7 +++++-- plugins/scaffolder-backend/api-report.md | 2 +- .../actions/builtin/github/OctokitProvider.ts | 7 +++++-- .../actions/builtin/publish/githubPullRequest.ts | 11 ++++++++--- 7 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.changeset/cold-toes-sniff.md b/.changeset/cold-toes-sniff.md index 0b79abd5aa..7fcfb54408 100644 --- a/.changeset/cold-toes-sniff.md +++ b/.changeset/cold-toes-sniff.md @@ -2,4 +2,4 @@ '@backstage/integration': patch --- -Adds a new GitHub credentials provider. It handles multiple app configurations. It looks up the app configuration based on the url. +Adds a new GitHub credentials provider (DefaultGithubCredentialsProvider). It handles multiple app configurations. It looks up the app configuration based on the url. diff --git a/packages/integration/src/github/DefaultGithubCredentialsProvider.ts b/packages/integration/src/github/DefaultGithubCredentialsProvider.ts index f43eabe52f..112fd83db7 100644 --- a/packages/integration/src/github/DefaultGithubCredentialsProvider.ts +++ b/packages/integration/src/github/DefaultGithubCredentialsProvider.ts @@ -58,7 +58,11 @@ export class DefaultGithubCredentialsProvider * @example * ```ts * const { token, headers } = await getCredentials({ - * url: 'github.com/backstage/foobar' + * url: 'https://github.com/backstage/foobar' + * }) + * + * const { token, headers } = await getCredentials({ + * url: 'https://github.com/backstage' * }) * ``` * diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 2d5e29fea0..e9a985914f 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -1063,7 +1063,7 @@ export class GitHubOrgEntityProvider implements EntityProvider { orgUrl: string; gitHubConfig: GitHubIntegrationConfig; logger: Logger_2; - githubCredentialsProvider: GithubCredentialsProvider; + githubCredentialsProvider?: GithubCredentialsProvider; }); // (undocumented) connect(connection: EntityProviderConnection): Promise; diff --git a/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts b/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts index c161074de4..b1d44a55b5 100644 --- a/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts +++ b/plugins/catalog-backend/src/ingestion/providers/GitHubOrgEntityProvider.ts @@ -24,6 +24,7 @@ import { GithubCredentialsProvider, GitHubIntegrationConfig, ScmIntegrations, + SingleInstanceGithubCredentialsProvider, } from '@backstage/integration'; import { graphql } from '@octokit/graphql'; import { merge } from 'lodash'; @@ -81,10 +82,12 @@ export class GitHubOrgEntityProvider implements EntityProvider { orgUrl: string; gitHubConfig: GitHubIntegrationConfig; logger: Logger; - githubCredentialsProvider: GithubCredentialsProvider; + githubCredentialsProvider?: GithubCredentialsProvider; }, ) { - this.githubCredentialsProvider = options.githubCredentialsProvider; + this.githubCredentialsProvider = + options.githubCredentialsProvider || + SingleInstanceGithubCredentialsProvider.create(options.gitHubConfig); } getProviderName() { diff --git a/plugins/scaffolder-backend/api-report.md b/plugins/scaffolder-backend/api-report.md index f2f9830664..fde7d7d265 100644 --- a/plugins/scaffolder-backend/api-report.md +++ b/plugins/scaffolder-backend/api-report.md @@ -288,7 +288,7 @@ export function fetchContents({ export class OctokitProvider { constructor( integrations: ScmIntegrationRegistry, - githubCredentialsProvider: GithubCredentialsProvider, + githubCredentialsProvider?: GithubCredentialsProvider, ); // Warning: (tsdoc-param-tag-missing-hyphen) The @param block should be followed by a parameter name and then a hyphen // Warning: (ae-forgotten-export) The symbol "OctokitIntegration" needs to be exported by the entry point index.d.ts diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts index 4a8bb8bbf6..40c723005e 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/github/OctokitProvider.ts @@ -16,6 +16,7 @@ import { InputError } from '@backstage/errors'; import { + DefaultGithubCredentialsProvider, GithubCredentialsProvider, ScmIntegrationRegistry, } from '@backstage/integration'; @@ -38,10 +39,12 @@ export class OctokitProvider { constructor( integrations: ScmIntegrationRegistry, - githubCredentialsProvider: GithubCredentialsProvider, + githubCredentialsProvider?: GithubCredentialsProvider, ) { this.integrations = integrations; - this.githubCredentialsProvider = githubCredentialsProvider; + this.githubCredentialsProvider = + githubCredentialsProvider || + DefaultGithubCredentialsProvider.fromIntegrations(this.integrations); } /** diff --git a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts index e657c36e50..7b3e89ac2a 100644 --- a/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts +++ b/plugins/scaffolder-backend/src/scaffolder/actions/builtin/publish/githubPullRequest.ts @@ -20,6 +20,7 @@ import { parseRepoUrl, isExecutable } from './util'; import { GithubCredentialsProvider, ScmIntegrationRegistry, + SingleInstanceGithubCredentialsProvider, } from '@backstage/integration'; import { zipObject } from 'lodash'; import { createTemplateAction } from '../../createTemplateAction'; @@ -58,7 +59,7 @@ export type GithubPullRequestActionInput = { export type ClientFactoryInput = { integrations: ScmIntegrationRegistry; - githubCredentialsProvider: GithubCredentialsProvider; + githubCredentialsProvider?: GithubCredentialsProvider; host: string; owner: string; repo: string; @@ -77,7 +78,11 @@ export const defaultClientFactory = async ({ throw new InputError(`No integration for host ${host}`); } - const { token } = await githubCredentialsProvider.getCredentials({ + const credentialsProvider = + githubCredentialsProvider || + SingleInstanceGithubCredentialsProvider.create(integrationConfig); + + const { token } = await credentialsProvider.getCredentials({ url: `https://${host}/${encodeURIComponent(owner)}/${encodeURIComponent( repo, )}`, @@ -99,7 +104,7 @@ export const defaultClientFactory = async ({ interface CreateGithubPullRequestActionOptions { integrations: ScmIntegrationRegistry; - githubCredentialsProvider: GithubCredentialsProvider; + githubCredentialsProvider?: GithubCredentialsProvider; clientFactory?: (input: ClientFactoryInput) => Promise; }