From 95de90fd23c6776a960e79dd048497ce783b5c58 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 13 Nov 2025 23:10:51 -0800 Subject: [PATCH] feat: support auth for enterprise --- src/index.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/index.ts b/src/index.ts index 0eb760f..0fb8b2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -95,6 +95,32 @@ export async function getAuthOptionsForOrg( ); } +export async function getAuthOptionsForEnterprise( + enterprise: string, + appCreds: AppCredentials, + authNarrowing: AuthNarrowing = {}, + request?: RequestInterface, +) { + return await getAuthOptionsForInstallationId( + appCreds, + authNarrowing, + async (octokit) => { + const installations = await octokit.paginate(octokit.apps.listInstallations); + for (const installation of installations) { + if ( + installation.target_type === 'Enterprise' && + installation.account?.slug === enterprise + ) { + return installation.id; + } + } + + throw new Error('Failed to find installation for enterprise'); + }, + request, + ); +} + async function getAuthOptionsForInstallationId( appCreds: AppCredentials, authNarrowing: AuthNarrowing = {},