@@ -8,66 +8,68 @@ import { readCompressedJsonFileFallback } from '../read-json-file.js'
88const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
99const schemasPath = path . join ( __dirname , 'static/decorated' )
1010
11- export const operations = { }
12- fs . readdirSync ( schemasPath ) . forEach ( ( filename ) => {
13- // In staging deploys, the `.json` files might have been converted to
14- // to `.json.br`. The `readCompressedJsonFileFallback()` function
15- // can handle both but you need to call it with the `.json` filename.
16- const key = path . parse ( filename ) . name
17- const value = readCompressedJsonFileFallback ( path . join ( schemasPath , filename ) )
18- operations [ key ] = value
19- } )
20-
21- // Get initial set of keys that will be deleted once new keys are set
22- const openApiOperationKeys = Object . keys ( operations )
11+ export default async function getRest ( ) {
12+ const operations = { }
13+ fs . readdirSync ( schemasPath ) . forEach ( ( filename ) => {
14+ // In staging deploys, the `.json` files might have been converted to
15+ // to `.json.br`. The `readCompressedJsonFileFallback()` function
16+ // can handle both but you need to call it with the `.json` filename.
17+ const key = path . parse ( filename ) . name
18+ const value = readCompressedJsonFileFallback ( path . join ( schemasPath , filename ) )
19+ operations [ key ] = value
20+ } )
2321
24- let allCategories = [ ]
25- allVersionKeys . forEach ( ( currentVersion ) => {
26- // Translate the versions from the openapi to versions used in the docs
27- const openApiVersion = allVersions [ currentVersion ] . openApiVersionName
22+ // Get initial set of keys that will be deleted once new keys are set
23+ const openApiOperationKeys = Object . keys ( operations )
2824
29- // Check that the openApiVersion is configured in OpenAPI
30- if ( ! operations [ openApiVersion ] ) return
25+ let allCategories = [ ]
26+ allVersionKeys . forEach ( ( currentVersion ) => {
27+ // Translate the versions from the openapi to versions used in the docs
28+ const openApiVersion = allVersions [ currentVersion ] . openApiVersionName
3129
32- operations [ currentVersion ] = operations [ openApiVersion ]
30+ // Check that the openApiVersion is configured in OpenAPI
31+ if ( ! operations [ openApiVersion ] ) return
3332
34- // This list is generated for use in the tests,
35- // so we can verify that the names of the markdown files
36- // in content/rest/reference/*.md are congruous with the
37- // set of REST resource names like activity, gists, repos, etc.
38- allCategories = allCategories . concat (
39- chain ( operations [ currentVersion ] ) . map ( 'category' ) . sort ( ) . uniq ( ) . value ( )
40- )
33+ operations [ currentVersion ] = operations [ openApiVersion ]
4134
42- // Attach convenience properties to each operation that can't easily be created in Liquid
43- operations [ currentVersion ] . forEach ( ( operation ) => {
44- operation . hasRequiredPreviews = get ( operation , 'x-github.previews' , [ ] ) . some (
45- ( preview ) => preview . required
35+ // This list is generated for use in the tests,
36+ // so we can verify that the names of the markdown files
37+ // in content/rest/reference/*.md are congruous with the
38+ // set of REST resource names like activity, gists, repos, etc.
39+ allCategories = allCategories . concat (
40+ chain ( operations [ currentVersion ] ) . map ( 'category' ) . sort ( ) . uniq ( ) . value ( )
4641 )
42+
43+ // Attach convenience properties to each operation that can't easily be created in Liquid
44+ operations [ currentVersion ] . forEach ( ( operation ) => {
45+ operation . hasRequiredPreviews = get ( operation , 'x-github.previews' , [ ] ) . some (
46+ ( preview ) => preview . required
47+ )
48+ } )
4749 } )
48- } )
4950
50- // Get the unique set of categories
51- const categories = [ ...new Set ( allCategories ) ]
51+ // Get the unique set of categories
52+ const categories = [ ...new Set ( allCategories ) ]
5253
53- // Remove openapi base name keys that have been replaced with version key
54- openApiOperationKeys . forEach ( ( openApiVersionName ) => {
55- delete operations [ openApiVersionName ]
56- } )
54+ // Remove openapi base name keys that have been replaced with version key
55+ openApiOperationKeys . forEach ( ( openApiVersionName ) => {
56+ delete operations [ openApiVersionName ]
57+ } )
5758
58- // This is a collection of operations that have `enabledForGitHubApps = true`
59- // It's grouped by resource title to make rendering easier
60- const operationsEnabledForGitHubApps = allVersionKeys . reduce ( ( acc , currentVersion ) => {
61- acc [ currentVersion ] = chain ( operations [ currentVersion ] || [ ] )
62- . filter ( ( operation ) => operation [ 'x-github' ] . enabledForGitHubApps )
63- . orderBy ( 'category' )
64- . value ( )
65- acc [ currentVersion ] = groupBy ( acc [ currentVersion ] , 'category' )
66- return acc
67- } , { } )
59+ // This is a collection of operations that have `enabledForGitHubApps = true`
60+ // It's grouped by resource title to make rendering easier
61+ const operationsEnabledForGitHubApps = allVersionKeys . reduce ( ( acc , currentVersion ) => {
62+ acc [ currentVersion ] = chain ( operations [ currentVersion ] || [ ] )
63+ . filter ( ( operation ) => operation [ 'x-github' ] . enabledForGitHubApps )
64+ . orderBy ( 'category' )
65+ . value ( )
66+ acc [ currentVersion ] = groupBy ( acc [ currentVersion ] , 'category' )
67+ return acc
68+ } , { } )
6869
69- export default {
70- categories,
71- operations,
72- operationsEnabledForGitHubApps,
70+ return {
71+ categories,
72+ operations,
73+ operationsEnabledForGitHubApps,
74+ }
7375}
0 commit comments