update tests with enterprise-slug

This commit is contained in:
Stefan Petrushevski
2025-08-28 10:23:07 +02:00
parent 22e6bc6b49
commit 6cf7b5f22a
14 changed files with 118 additions and 72 deletions
+11 -11
View File
@@ -34,8 +34,8 @@ export async function main(
let parsedOwner = "";
let parsedRepositoryNames = [];
// Skip owner/repository parsing if enterprise is set
if (!enterprise) {
// Skip owner/repository parsing if enterprise-slug is set
if (!enterpriseSlug) {
// If neither owner nor repositories are set, default to current repository
if (!owner && repositories.length === 0) {
const [owner, repo] = String(process.env.GITHUB_REPOSITORY).split("/");
@@ -75,11 +75,11 @@ export async function main(
core.info(
`Inputs 'owner' and 'repositories' are set. Creating token for the following repositories:
${repositories.map((repo) => `\n- ${parsedOwner}/${repo}`).join("")}`
${repositories.map((repo) => `\n- ${parsedOwner}/${repo}`).join("")}`
);
}
} else {
core.info(`Creating enterprise installation token for enterprise "${enterprise}".`);
core.info(`Creating enterprise installation token for enterprise "${enterpriseSlug}".`);
}
const auth = createAppAuth({
@@ -90,15 +90,15 @@ export async function main(
let authentication, installationId, appSlug;
// If enterprise is set, get installation ID from the enterprise
if (enterprise) {
// If enterprise-slug is set, get installation ID from the enterprise
if (enterpriseSlug) {
({ authentication, installationId, appSlug } = await pRetry(
() => getTokenFromEnterprise(request, auth, enterprise, permissions),
() => getTokenFromEnterprise(request, auth, enterpriseSlug, permissions),
{
shouldRetry: (error) => error.status >= 500,
onFailedAttempt: (error) => {
core.info(
`Failed to create token for enterprise "${enterprise}" (attempt ${error.attemptNumber}): ${error.message}`
`Failed to create token for enterprise "${enterpriseSlug}" (attempt ${error.attemptNumber}): ${error.message}`
);
},
retries: 3,
@@ -208,7 +208,7 @@ async function getTokenFromRepository(
return { authentication, installationId, appSlug };
}
async function getTokenFromEnterprise(request, auth, enterprise, permissions) {
async function getTokenFromEnterprise(request, auth, enterpriseSlug, permissions) {
// Get all installations and find the enterprise one
// https://docs.github.com/rest/apps/apps#list-installations-for-the-authenticated-app
// Note: Currently we do not have a way to get the installation for an enterprise directly,
@@ -222,11 +222,11 @@ async function getTokenFromEnterprise(request, auth, enterprise, permissions) {
// Find the enterprise installation
const enterpriseInstallation = response.data.find(
installation => installation.target_type === "Enterprise" &&
installation.account?.slug === enterprise
installation.account?.slug === enterpriseSlug
);
if (!enterpriseInstallation) {
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(', ')}`);
throw new Error(`No enterprise installation found matching the name ${enterpriseSlug}. Available installations: ${response.data.map(i => `${i.target_type}:${i.account?.login || 'N/A'}`).join(', ')}`);
}
// Get token for the enterprise installation