Skip to content

Commit 14bfa57

Browse files
graceparkrachmari
andauthored
Update enabled apps to use openapi version (#32327)
Co-authored-by: Rachael Sewell <[email protected]>
1 parent 8550293 commit 14bfa57

File tree

3 files changed

+16
-41
lines changed

3 files changed

+16
-41
lines changed

lib/rest/index.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ export default async function getRest(version, category, subCategory) {
6565
}
6666
}
6767

68-
function getDocsVersion(openApiVersion) {
69-
const version = Object.values(allVersions).find(
70-
(version) => version.openApiVersionName === openApiVersion
71-
).version
72-
return version
73-
}
74-
7568
function getOpenApiVersion(version) {
7669
if (!(version in allVersions)) {
7770
throw new Error(`Unrecognized version '${version}'. Not found in ${Object.keys(allVersions)}`)
@@ -104,14 +97,16 @@ export async function getRestMiniTocItems(
10497
return restOperationData.get(language).get(version).get(category).get(subCategory)
10598
}
10699

107-
export async function getEnabledForApps() {
108-
// The `readCompressedJsonFileFallback()` function
109-
// will check for both a .br and .json extension.
110-
const appsData = readCompressedJsonFileFallback(ENABLED_APPS_FILENAME)
111-
for (const version in appsData) {
112-
const docsVersion = getDocsVersion(version)
113-
appsData[docsVersion] = appsData[version]
114-
delete appsData[version]
100+
const enabledForApps = {}
101+
export async function getEnabledForApps(docsVersion) {
102+
if (Object.keys(enabledForApps).length === 0) {
103+
// The `readCompressedJsonFileFallback()` function
104+
// will check for both a .br and .json extension.
105+
Object.assign(enabledForApps, readCompressedJsonFileFallback(ENABLED_APPS_FILENAME))
106+
107+
// One off edge case where secret-scanning should be removed from FPT. Docs Content #6637
108+
delete enabledForApps['api.github.com']['secret-scanning']
115109
}
116-
return appsData
110+
const openApiVersion = getOpenApiVersion(docsVersion)
111+
return enabledForApps[openApiVersion]
117112
}

pages/[versionId]/rest/overview/endpoints-available-for-github-apps.tsx

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ type EnabledAppCategoryT = {
2323
[category: string]: OperationT[]
2424
}
2525

26-
type AppDataT = {
27-
[version: string]: EnabledAppCategoryT
28-
}
29-
30-
let enabledForApps: AppDataT | null = null
31-
3226
type Props = {
3327
mainContext: MainContextT
3428
currentVersion: string
@@ -91,25 +85,17 @@ export default function Category({
9185
export const getServerSideProps: GetServerSideProps<Props> = async (context) => {
9286
const req = context.req as object
9387
const res = context.res as object
94-
const currentVersion = context.query.versionId as string
9588
const mainContext = await getMainContext(req, res)
9689
const automatedPageContext = getAutomatedPageContextFromRequest(req)
90+
const currentVersion = context.query.versionId as string
9791

98-
if (!enabledForApps) {
99-
enabledForApps = (await getEnabledForApps()) as AppDataT
100-
}
101-
102-
// One off edge case where secret-scanning should be removed from FPT. Docs Content #6637
103-
const noSecretScanning = { ...enabledForApps[currentVersion] }
104-
delete noSecretScanning['secret-scanning']
105-
const overrideEnabledForApps =
106-
currentVersion === 'free-pro-team@latest' ? noSecretScanning : enabledForApps[currentVersion]
92+
const enabledForApps = await getEnabledForApps(currentVersion)
10793

10894
return {
10995
props: {
11096
mainContext,
11197
currentVersion,
112-
enabledForApps: overrideEnabledForApps,
98+
enabledForApps,
11399
automatedPageContext,
114100
categoriesWithoutSubcategories,
115101
},

tests/rendering/rest.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,12 @@ describe('REST references docs', () => {
2828
// and ensures that all sections in the openapi schema
2929
// are present in the page.
3030
test('loads operations enabled for GitHub Apps', async () => {
31-
const enabledForApps = await getEnabledForApps()
32-
3331
for (const version in allVersions) {
32+
const enabledForApps = await getEnabledForApps(version)
3433
const schemaSlugs = []
35-
// One off edge case where secret-scanning should be removed from FPT. Docs Content #6637
36-
const noSecretScanning = { ...enabledForApps[version] }
37-
delete noSecretScanning['secret-scanning']
38-
const overrideEnabledForApps =
39-
version === 'free-pro-team@latest' ? noSecretScanning : enabledForApps[version]
4034

4135
// using the static file, generate the expected slug for each operation
42-
for (const [key, value] of Object.entries(overrideEnabledForApps)) {
36+
for (const [key, value] of Object.entries(enabledForApps)) {
4337
schemaSlugs.push(
4438
...value.map(
4539
(item) =>

0 commit comments

Comments
 (0)