Skip to content

Commit

Permalink
Use octokit REST API for creating installation access token (tibdex#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
abebehailu authored Oct 16, 2022
1 parent 9edcc8a commit 8905248
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/fetch-installation-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand All @@ -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),
});
}
};

0 comments on commit 8905248

Please sign in to comment.