From 46f9f788b8824135a13ac16ab36abcba846e99a5 Mon Sep 17 00:00:00 2001 From: Stefan Petrushevski Date: Tue, 8 Jul 2025 17:52:25 +0200 Subject: [PATCH] improve installation match; refactor test per copilot review --- dist/main.cjs | 5 ++--- lib/main.js | 7 +++---- tests/main-enterprise-installation-not-found.test.js | 5 +++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dist/main.cjs b/dist/main.cjs index 434f543..2931c58 100644 --- a/dist/main.cjs +++ b/dist/main.cjs @@ -42667,12 +42667,11 @@ async function getTokenFromEnterprise(request2, auth5, enterprise2, permissions2 } }); const enterpriseInstallation = response.data.find( - (installation) => installation.target_type === "Enterprise" + (installation) => installation.target_type === "Enterprise" && installation.account?.slug === enterprise2 ); if (!enterpriseInstallation) { - throw new Error(`No enterprise installation found. Available installations: ${response.data.map((i) => `${i.target_type}:${i.account?.login || "N/A"}`).join(", ")}`); + throw new Error(`No enterprise installation found matching the name ${enterprise2}. Available installations: ${response.data.map((i) => `${i.target_type}:${i.account?.login || "N/A"}`).join(", ")}`); } - console.info(`### Found enterprise installation: ${JSON.stringify(enterpriseInstallation, null, 2)}`); const authentication = await auth5({ type: "installation", installationId: enterpriseInstallation.id, diff --git a/lib/main.js b/lib/main.js index 475f233..e9c83b0 100644 --- a/lib/main.js +++ b/lib/main.js @@ -221,15 +221,14 @@ async function getTokenFromEnterprise(request, auth, enterprise, permissions) { // Find the enterprise installation const enterpriseInstallation = response.data.find( - installation => installation.target_type === "Enterprise" + installation => installation.target_type === "Enterprise" && + installation.account?.slug === enterprise ); if (!enterpriseInstallation) { - throw new Error(`No enterprise installation found. Available installations: ${response.data.map(i => `${i.target_type}:${i.account?.login || 'N/A'}`).join(', ')}`); + throw new Error(`No enterprise installation found matching the name ${enterprise}. Available installations: ${response.data.map(i => `${i.target_type}:${i.account?.login || 'N/A'}`).join(', ')}`); } - console.info(`### Found enterprise installation: ${JSON.stringify(enterpriseInstallation, null, 2)}`); - // Get token for the enterprise installation const authentication = await auth({ type: "installation", diff --git a/tests/main-enterprise-installation-not-found.test.js b/tests/main-enterprise-installation-not-found.test.js index ca27b31..c5a492d 100644 --- a/tests/main-enterprise-installation-not-found.test.js +++ b/tests/main-enterprise-installation-not-found.test.js @@ -1,9 +1,10 @@ import { test } from "./main.js"; -delete process.env.INPUT_OWNER; -delete process.env.INPUT_REPOSITORIES; + // Verify `main` handles when no enterprise installation is found. await test((mockPool) => { + delete process.env.INPUT_OWNER; + delete process.env.INPUT_REPOSITORIES; process.env.INPUT_ENTERPRISE = "test-enterprise";