From 629d20365636eae76e7358bb0b39bb69270cbc64 Mon Sep 17 00:00:00 2001 From: Abebe Hailu Date: Fri, 30 Sep 2022 13:06:21 +0200 Subject: [PATCH] Use octoki rest api for creating installation access token --- src/fetch-installation-token.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fetch-installation-token.ts b/src/fetch-installation-token.ts index 069d7c2e..a73e8da9 100644 --- a/src/fetch-installation-token.ts +++ b/src/fetch-installation-token.ts @@ -29,9 +29,9 @@ export const fetchInstallationToken = async ({ }), }); + const authApp = await app({ type: "app" }); + const octokit = getOctokit(authApp.token); if (installationId === undefined) { - const authApp = await app({ type: "app" }); - const octokit = getOctokit(authApp.token); try { ({ data: { id: installationId }, @@ -44,10 +44,16 @@ export const fetchInstallationToken = async ({ } } - const installation = await app({ - installationId, - permissions, - type: "installation", - }); - return installation.token; + try { + const { data: installation } = + await octokit.rest.apps.createInstallationAccessToken({ + installation_id: installationId, + permissions, + }); + return installation?.token; + } catch (error: unknown) { + throw new Error("Could not create installation access token.", { + cause: ensureError(error), + }); + } };