1
0
mirror of synced 2025-12-19 18:10:59 -05:00

break version-specific data into individual files (#34717)

This commit is contained in:
Rachael Sewell
2023-02-15 11:03:08 -08:00
committed by GitHub
parent 8babc127b2
commit 6b4d76e09c
16 changed files with 28832 additions and 28832 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,21 @@
import { readCompressedJsonFileFallback } from '../../../lib/read-json-file.js'
import { getOpenApiVersion } from '../../../lib/all-versions.js'
export const ENABLED_APPS_DIR = 'src/github-apps/data'
export const ENABLED_APPS_FILENAME = 'server-to-server-rest.json'
const enabledForApps = new Map()
export async function getEnabledForApps(docsVersion, apiVersion) {
const openApiVersion = getOpenApiVersion(docsVersion) + (apiVersion ? `.${apiVersion}` : '')
if (!enabledForApps.has(openApiVersion)) {
// The `readCompressedJsonFileFallback()` function
// will check for both a .br and .json extension.
const data = readCompressedJsonFileFallback(
`${ENABLED_APPS_DIR}/${openApiVersion}/${ENABLED_APPS_FILENAME}`
)
enabledForApps.set(openApiVersion, data)
}
return enabledForApps.get(openApiVersion)
}

View File

@@ -3,11 +3,11 @@ import path from 'path'
import { readCompressedJsonFileFallback } from '../../../lib/read-json-file.js'
import { getAutomatedPageMiniTocItems } from '../../../lib/get-mini-toc-items.js'
import { allVersions } from '../../../lib/all-versions.js'
import { allVersions, getOpenApiVersion } from '../../../lib/all-versions.js'
import languages from '../../../lib/languages.js'
const schemasPath = 'src/rest/data'
const ENABLED_APPS_FILENAME = 'src/github-apps/data/enabled-for-apps.json'
const contentPath = 'content/rest'
/*
@@ -100,13 +100,6 @@ export default async function getRest(version, apiVersion, category, subCategory
}
}
function getOpenApiVersion(version) {
if (!(version in allVersions)) {
throw new Error(`Unrecognized version '${version}'. Not found in ${Object.keys(allVersions)}`)
}
return allVersions[version].openApiVersionName
}
// Generates the miniToc for a rest reference page.
export async function getRestMiniTocItems(
category,
@@ -134,15 +127,3 @@ export async function getRestMiniTocItems(
}
return restOperationData.get(language).get(version).get(apiDate).get(category).get(subCategory)
}
const enabledForApps = {}
export async function getEnabledForApps(docsVersion, apiVersion) {
if (Object.keys(enabledForApps).length === 0) {
// The `readCompressedJsonFileFallback()` function
// will check for both a .br and .json extension.
Object.assign(enabledForApps, readCompressedJsonFileFallback(ENABLED_APPS_FILENAME))
}
const openApiVersion = getOpenApiVersion(docsVersion) + (apiVersion ? `.${apiVersion}` : '')
return enabledForApps[openApiVersion]
}

View File

@@ -6,8 +6,9 @@ import { slug } from 'github-slugger'
import { allVersions } from '../../../../lib/all-versions.js'
import { categoriesWithoutSubcategories } from '../../lib/index.js'
import getOperations, { getWebhooks } from './get-operations.js'
import { ENABLED_APPS_DIR, ENABLED_APPS_FILENAME } from '../../../github-apps/lib/index.js'
import { WEBHOOK_DATA_DIR, WEBHOOK_SCHEMA_FILENAME } from '../../../webhooks/lib/index.js'
const ENABLED_APPS = 'src/github-apps/data/enabled-for-apps.json'
const STATIC_REDIRECTS = 'lib/redirects/static/client-side-rest-api-redirects.json'
const REST_DECORATED_DIR = 'src/rest/data'
const REST_DEREFERENCED_DIR = 'src/rest/data/dereferenced'
@@ -66,7 +67,6 @@ async function getWebhookOperations(webhookSchemas) {
}
async function createStaticRestFiles(restOperations) {
const operationsEnabledForGitHubApps = {}
const clientSideRedirects = await getCategoryOverrideRedirects()
for (const schemaName in restOperations) {
const operations = restOperations[schemaName]
@@ -129,15 +129,17 @@ async function createStaticRestFiles(restOperations) {
await writeFile(restFilename, JSON.stringify(operationsByCategory, null, 2))
console.log('Wrote', path.relative(process.cwd(), restFilename))
// Create the enabled-for-apps.json file used for
// Create the src/github-apps/data files used for
// https://docs.github.com/en/rest/overview/endpoints-available-for-github-apps
operationsEnabledForGitHubApps[schemaName] = {}
const enabledAppsFilename = path.join(ENABLED_APPS_DIR, schemaName, ENABLED_APPS_FILENAME)
const enabledAppsVersionDir = path.join(ENABLED_APPS_DIR, schemaName)
const operationsEnabledForGitHubApps = {}
for (const category of categories) {
const categoryOperations = operations.filter((operation) => operation.category === category)
// This is a collection of operations that have `enabledForGitHubApps = true`
// It's grouped by resource title to make rendering easier
operationsEnabledForGitHubApps[schemaName][category] = categoryOperations
operationsEnabledForGitHubApps[category] = categoryOperations
.filter((operation) => operation.enabledForGitHubApps)
.map((operation) => ({
slug: slug(operation.title),
@@ -146,10 +148,14 @@ async function createStaticRestFiles(restOperations) {
requestPath: operation.requestPath,
}))
}
// When a new version is added, we need to create the directory for it
if (!existsSync(enabledAppsVersionDir)) {
mkdirSync(enabledAppsVersionDir)
}
await writeFile(enabledAppsFilename, JSON.stringify(operationsEnabledForGitHubApps, null, 2))
console.log('Wrote', enabledAppsFilename)
}
await writeFile(ENABLED_APPS, JSON.stringify(operationsEnabledForGitHubApps, null, 2))
console.log('Wrote', ENABLED_APPS)
await writeFile(STATIC_REDIRECTS, JSON.stringify(clientSideRedirects, null, 2), 'utf8')
console.log('Wrote', STATIC_REDIRECTS)
}

View File

@@ -1,6 +1,6 @@
import path from 'path'
import { allVersions } from '../../../lib/all-versions.js'
import { getOpenApiVersion } from '../../../lib/all-versions.js'
import { readCompressedJsonFileFallback } from '../../../lib/read-json-file.js'
export const WEBHOOK_DATA_DIR = 'src/webhooks/data'
@@ -75,10 +75,3 @@ export async function getWebhooks(version) {
return webhooksCache.get(openApiVersion)
}
function getOpenApiVersion(version) {
if (!(version in allVersions)) {
throw new Error(`Unrecognized version '${version}'. Not found in ${Object.keys(allVersions)}`)
}
return allVersions[version].openApiVersionName
}