1
0
mirror of synced 2026-02-02 06:01:58 -05:00

Update OpenAPI workflow to use new GitHub directory format (#52578)

This commit is contained in:
Rachael Sewell
2024-10-09 00:50:26 +00:00
committed by GitHub
parent 34ad027c08
commit 93ea4ec79d
2 changed files with 84 additions and 8 deletions

View File

@@ -255,3 +255,28 @@ async function secondaryRateLimitRetry(callable, args, maxAttempts = 10, sleepTi
throw err
}
}
// Recursively gets the contents of a directory within a repo. Returns an
// array of file contents. This function could be modified to return an array
// of objects that include the path and the content of the file if needed
// in the future.
export async function getDirectoryContents(owner, repo, branch, path) {
const { data } = await getContent(owner, repo, branch, path)
const files = []
for (const blob of data) {
if (blob.type === 'dir') {
files.push(...(await getDirectoryContents(owner, repo, branch, blob.path)))
} else if (blob.type === 'file') {
if (!data.content) {
const blobContents = await getContentsForBlob(owner, repo, blob.sha)
files.push(blobContents)
} else {
// decode Base64 encoded contents
const decodedContent = Buffer.from(blob.content, 'base64').toString()
files.push(decodedContent)
}
}
}
return files
}