From 3ab18ce88cb7e3424c3cef391c75b10ef591bf3e Mon Sep 17 00:00:00 2001 From: Rachael Sewell Date: Thu, 15 Feb 2024 14:07:29 -0800 Subject: [PATCH] Fix local github checkout bug in openapi sync (#49239) --- src/github-apps/scripts/sync.js | 9 +++++---- src/rest/scripts/update-files.js | 8 ++++---- src/rest/scripts/utils/sync.js | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/github-apps/scripts/sync.js b/src/github-apps/scripts/sync.js index 5d5c80acc5..f12b5a3ef0 100644 --- a/src/github-apps/scripts/sync.js +++ b/src/github-apps/scripts/sync.js @@ -15,7 +15,7 @@ import { validateJson } from '#src/tests/lib/validate-json-schema.js' const ENABLED_APPS_DIR = 'src/github-apps/data' const CONFIG_FILE = 'src/github-apps/lib/config.json' -export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAccessSource = false) { +export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAccessSource) { const { progAccessData, progActorResources } = await getProgAccessData(progAccessSource) for (const schemaName of sourceSchemas) { @@ -153,9 +153,10 @@ export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAcces } } -export async function getProgAccessData(progAccessSource = false) { +export async function getProgAccessData(progAccessSource) { + const useRemoteGitHubFiles = progAccessSource === 'rest-api-description' // check for required PAT - if (progAccessSource && !process.env.GITHUB_TOKEN) { + if (useRemoteGitHubFiles && !process.env.GITHUB_TOKEN) { throw new Error( 'Error! You must have the GITHUB_TOKEN environment variable set to access the programmatic access and resource files via the GitHub REST API.', ) @@ -167,7 +168,7 @@ export async function getProgAccessData(progAccessSource = false) { const progAccessFilepath = 'config/access_control/programmatic_access.yaml' const progActorFilepath = 'config/locales/programmatic_actor_fine_grained_resources.en.yml' - if (progAccessSource) { + if (!useRemoteGitHubFiles) { progAccessDataRaw = yaml.load( await readFile(path.join(progAccessSource, progAccessFilepath), 'utf8'), ) diff --git a/src/rest/scripts/update-files.js b/src/rest/scripts/update-files.js index b3e58aa34a..914a056273 100755 --- a/src/rest/scripts/update-files.js +++ b/src/rest/scripts/update-files.js @@ -65,6 +65,8 @@ program const { versions, includeUnpublished, includeDeprecated, next, output, sourceRepo } = program.opts() +const sourceRepoDirectory = sourceRepo === 'github' ? GITHUB_REP_DIR : REST_API_DESCRIPTION_ROOT + main() async function main() { @@ -122,11 +124,10 @@ async function main() { } const derefFiles = await readdir(TEMP_OPENAPI_DIR) const { restSchemas, webhookSchemas } = await getOpenApiSchemaFiles(derefFiles) - const progAccessSource = sourceRepo === 'github' && GITHUB_REP_DIR if (pipelines.includes('rest')) { console.log(`\n▶️ Generating REST data files...\n`) - await syncRestData(TEMP_OPENAPI_DIR, restSchemas, progAccessSource) + await syncRestData(TEMP_OPENAPI_DIR, restSchemas, sourceRepoDirectory) } if (pipelines.includes('webhooks')) { @@ -136,7 +137,7 @@ async function main() { if (pipelines.includes('github-apps')) { console.log(`\n▶️ Generating GitHub Apps data files...\n`) - await syncGitHubAppsData(TEMP_OPENAPI_DIR, restSchemas, progAccessSource) + await syncGitHubAppsData(TEMP_OPENAPI_DIR, restSchemas, sourceRepoDirectory) } if (pipelines.includes('rest-redirects')) { @@ -236,7 +237,6 @@ async function validateInputParameters() { } // Check that the source repo exists. - const sourceRepoDirectory = sourceRepo === 'github' ? GITHUB_REP_DIR : REST_API_DESCRIPTION_ROOT if (!existsSync(sourceRepoDirectory)) { const errorMsg = sourceRepo === 'github' diff --git a/src/rest/scripts/utils/sync.js b/src/rest/scripts/utils/sync.js index 46eb0cbaae..2dba7edbf5 100644 --- a/src/rest/scripts/utils/sync.js +++ b/src/rest/scripts/utils/sync.js @@ -16,7 +16,7 @@ const OPENAPI_VERSION_NAMES = Object.keys(allVersions).map( (elem) => allVersions[elem].openApiVersionName, ) -export async function syncRestData(sourceDirectory, restSchemas, progAccessSource = false) { +export async function syncRestData(sourceDirectory, restSchemas, progAccessSource) { await Promise.all( restSchemas.map(async (schemaName) => { const file = path.join(sourceDirectory, schemaName)