From 3fc738a55c494da8c577da1e9b021ad8c517c041 Mon Sep 17 00:00:00 2001 From: ebarrios Date: Tue, 16 Feb 2021 12:58:15 +0100 Subject: [PATCH] modify change set to path, simplify to one expresion the check for config.token and config.apps and deconstructed the response fron the credentialProvider.getCredentials function --- .changeset/loud-owls-beam.md | 2 +- .../src/scaffolder/stages/publish/github.ts | 19 +++++++++---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.changeset/loud-owls-beam.md b/.changeset/loud-owls-beam.md index f17b23223b..764bfdf72a 100644 --- a/.changeset/loud-owls-beam.md +++ b/.changeset/loud-owls-beam.md @@ -1,5 +1,5 @@ --- -'@backstage/plugin-scaffolder-backend': minor +'@backstage/plugin-scaffolder-backend': patch --- Added githubApp authentication to the scaffolder-backend plugin diff --git a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts index 1846cb90d1..365b3f14cd 100644 --- a/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts +++ b/plugins/scaffolder-backend/src/scaffolder/stages/publish/github.ts @@ -31,10 +31,8 @@ export class GithubPublisher implements PublisherBase { config: GitHubIntegrationConfig, { repoVisibility }: { repoVisibility: RepoVisibilityOptions }, ) { - if (!config.token) { - if (!config.apps) { - return undefined; - } + if (!config.token && !config.apps) { + return undefined; } const credentialsProvider = GithubCredentialsProvider.create(config); @@ -61,12 +59,13 @@ export class GithubPublisher implements PublisherBase { }: PublisherOptions): Promise { const { owner, name } = parseGitUrl(values.storePath); - const token = - ( - await this.config.credentialsProvider.getCredentials({ - url: values.storePath, - }) - ).token || ''; + const { token } = await this.config.credentialsProvider.getCredentials({ + url: values.storePath, + }); + + if (!token) { + return { remoteUrl: '', catalogInfoUrl: undefined }; + } const client = new Octokit({ auth: token,