update tests with enterprise-slug
This commit is contained in:
+11
-11
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user