import { readFile, writeFile } from "node:fs/promises"; import OctokitOpenapi from "@octokit/openapi"; const appPermissionsSchema = OctokitOpenapi.schemas["api.github.com"].components.schemas[ "app-permissions" ]; await writeFile( `scripts/generated/app-permissions.json`, JSON.stringify(appPermissionsSchema, null, 2) + "\n", "utf8" ); const permissionsInputs = Object.entries(appPermissionsSchema.properties) .sort((a, b) => a[0].localeCompare(b[0])) .reduce((result, [key, value]) => { const formatter = new Intl.ListFormat("en", { style: "long", type: "disjunction", }); const permissionAccessValues = formatter.format( value.enum.map((p) => `'${p}'`) ); const description = `${value.description} Can be set to ${permissionAccessValues}.`; return `${result} permission-${key.replace(/_/g, "-")}: description: "${description}"`; }, ""); const actionsYamlContent = await readFile("action.yml", "utf8"); // In the action.yml file, replace the content between the `` and `` comments with the new content const updatedActionsYamlContent = actionsYamlContent.replace( /(?<=# )(.|\n)*(?=# )/, permissionsInputs + "\n " ); await writeFile("action.yml", updatedActionsYamlContent, "utf8"); console.log("Updated action.yml with new permissions inputs");