From d0e8705afd554e953e011696aea75c39c9d3febf Mon Sep 17 00:00:00 2001 From: Alex Crome Date: Mon, 5 Sep 2022 22:05:29 +0100 Subject: [PATCH] Moved Github Installation loading to be within cached data Signed-off-by: Alex Crome --- .../SingleInstanceGithubCredentialsProvider.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.ts b/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.ts index 8b87d985a5..5e98ddd3b1 100644 --- a/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.ts +++ b/packages/integration/src/github/SingleInstanceGithubCredentialsProvider.ts @@ -99,19 +99,22 @@ class GithubAppManager { } } - const { installationId, suspended } = await this.getInstallationData(owner); - if (suspended) { - throw new Error(`The GitHub application for ${owner} is suspended`); - } - const cacheKey = repo ? `${owner}/${repo}` : owner; // Go and grab an access token for the app scoped to a repository if provided, if not use the organisation installation. return this.cache.getOrCreateToken(cacheKey, async () => { + const { installationId, suspended } = await this.getInstallationData( + owner, + ); + if (suspended) { + throw new Error(`The GitHub application for ${owner} is suspended`); + } + const result = await this.appClient.apps.createInstallationAccessToken({ installation_id: installationId, headers: HEADERS, }); + if (repo && result.data.repository_selection === 'selected') { const installationClient = new Octokit({ baseUrl: this.baseUrl,