Skip to content

Commit 3ab18ce

Browse files
authored
Fix local github checkout bug in openapi sync (#49239)
1 parent f2c7f77 commit 3ab18ce

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/github-apps/scripts/sync.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { validateJson } from '#src/tests/lib/validate-json-schema.js'
1515
const ENABLED_APPS_DIR = 'src/github-apps/data'
1616
const CONFIG_FILE = 'src/github-apps/lib/config.json'
1717

18-
export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAccessSource = false) {
18+
export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAccessSource) {
1919
const { progAccessData, progActorResources } = await getProgAccessData(progAccessSource)
2020

2121
for (const schemaName of sourceSchemas) {
@@ -153,9 +153,10 @@ export async function syncGitHubAppsData(openApiSource, sourceSchemas, progAcces
153153
}
154154
}
155155

156-
export async function getProgAccessData(progAccessSource = false) {
156+
export async function getProgAccessData(progAccessSource) {
157+
const useRemoteGitHubFiles = progAccessSource === 'rest-api-description'
157158
// check for required PAT
158-
if (progAccessSource && !process.env.GITHUB_TOKEN) {
159+
if (useRemoteGitHubFiles && !process.env.GITHUB_TOKEN) {
159160
throw new Error(
160161
'Error! You must have the GITHUB_TOKEN environment variable set to access the programmatic access and resource files via the GitHub REST API.',
161162
)
@@ -167,7 +168,7 @@ export async function getProgAccessData(progAccessSource = false) {
167168
const progAccessFilepath = 'config/access_control/programmatic_access.yaml'
168169
const progActorFilepath = 'config/locales/programmatic_actor_fine_grained_resources.en.yml'
169170

170-
if (progAccessSource) {
171+
if (!useRemoteGitHubFiles) {
171172
progAccessDataRaw = yaml.load(
172173
await readFile(path.join(progAccessSource, progAccessFilepath), 'utf8'),
173174
)

src/rest/scripts/update-files.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ program
6565

6666
const { versions, includeUnpublished, includeDeprecated, next, output, sourceRepo } = program.opts()
6767

68+
const sourceRepoDirectory = sourceRepo === 'github' ? GITHUB_REP_DIR : REST_API_DESCRIPTION_ROOT
69+
6870
main()
6971

7072
async function main() {
@@ -122,11 +124,10 @@ async function main() {
122124
}
123125
const derefFiles = await readdir(TEMP_OPENAPI_DIR)
124126
const { restSchemas, webhookSchemas } = await getOpenApiSchemaFiles(derefFiles)
125-
const progAccessSource = sourceRepo === 'github' && GITHUB_REP_DIR
126127

127128
if (pipelines.includes('rest')) {
128129
console.log(`\n▶️ Generating REST data files...\n`)
129-
await syncRestData(TEMP_OPENAPI_DIR, restSchemas, progAccessSource)
130+
await syncRestData(TEMP_OPENAPI_DIR, restSchemas, sourceRepoDirectory)
130131
}
131132

132133
if (pipelines.includes('webhooks')) {
@@ -136,7 +137,7 @@ async function main() {
136137

137138
if (pipelines.includes('github-apps')) {
138139
console.log(`\n▶️ Generating GitHub Apps data files...\n`)
139-
await syncGitHubAppsData(TEMP_OPENAPI_DIR, restSchemas, progAccessSource)
140+
await syncGitHubAppsData(TEMP_OPENAPI_DIR, restSchemas, sourceRepoDirectory)
140141
}
141142

142143
if (pipelines.includes('rest-redirects')) {
@@ -236,7 +237,6 @@ async function validateInputParameters() {
236237
}
237238

238239
// Check that the source repo exists.
239-
const sourceRepoDirectory = sourceRepo === 'github' ? GITHUB_REP_DIR : REST_API_DESCRIPTION_ROOT
240240
if (!existsSync(sourceRepoDirectory)) {
241241
const errorMsg =
242242
sourceRepo === 'github'

src/rest/scripts/utils/sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const OPENAPI_VERSION_NAMES = Object.keys(allVersions).map(
1616
(elem) => allVersions[elem].openApiVersionName,
1717
)
1818

19-
export async function syncRestData(sourceDirectory, restSchemas, progAccessSource = false) {
19+
export async function syncRestData(sourceDirectory, restSchemas, progAccessSource) {
2020
await Promise.all(
2121
restSchemas.map(async (schemaName) => {
2222
const file = path.join(sourceDirectory, schemaName)

0 commit comments

Comments
 (0)