diff --git a/packages/integration/package.json b/packages/integration/package.json index b4134ab00e..254b4d3fe5 100644 --- a/packages/integration/package.json +++ b/packages/integration/package.json @@ -30,6 +30,7 @@ }, "dependencies": { "@backstage/config": "^0.1.2", + "@backstage/integration": "^0.4.0", "cross-fetch": "^3.0.6", "git-url-parse": "^11.4.4", "@octokit/rest": "^18.0.12", diff --git a/packages/integration/src/github/config.ts b/packages/integration/src/github/config.ts index 4b80a9aa60..2a998ef18b 100644 --- a/packages/integration/src/github/config.ts +++ b/packages/integration/src/github/config.ts @@ -16,6 +16,7 @@ import { Config } from '@backstage/config'; import { isValidHost } from '../helpers'; +import { GithubCredentialsProvider } from '@backstage/integration'; const GITHUB_HOST = 'github.com'; const GITHUB_API_BASE_URL = 'https://api.github.com'; @@ -60,11 +61,11 @@ export type GitHubIntegrationConfig = { token?: string; /** - * The accessType (oAuth|githubApp) to use for requests to this provider. + * The credentialsProvider to use for requests to this provider. * - * If no user is specified, oAuth access is used. + * If no credentialsProvider is created, undefined is used. */ - accessType?: string; + credentialsProvider?: GithubCredentialsProvider | undefined; /** * The GitHub Apps configuration to use for requests to this provider. diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 4dd872ad8f..4d038ed5b9 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -31,15 +31,13 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { - config.accessType = 'oAuth'; - - const credentialsProvider = GithubCredentialsProvider.create(config); + let credentialsProvider: GithubCredentialsProvider | undefined = undefined; if (!config.token) { if (!config.apps) { return undefined; } - config.accessType = 'githubApp'; + credentialsProvider = GithubCredentialsProvider.create(config); } const githubClient = new Octokit({ @@ -49,7 +47,6 @@ export class GithubPublisher implements PublisherBase { return new GithubPublisher({ token: config.token || '', - accessType: config.accessType, credentialsProvider, client: githubClient, repoVisibility, @@ -60,8 +57,7 @@ export class GithubPublisher implements PublisherBase { constructor( private readonly config: { token: string; - accessType: string; - credentialsProvider: GithubCredentialsProvider; + credentialsProvider: GithubCredentialsProvider | undefined; client: Octokit; repoVisibility: RepoVisibilityOptions; apiBaseUrl: string | undefined; @@ -80,7 +76,7 @@ export class GithubPublisher implements PublisherBase { password: 'x-oauth-basic', }; - if (this.config.accessType === 'githubApp') { + if (this.config.credentialsProvider) { this.config.token = ( await this.config.credentialsProvider.getCredentials({