* First run of script * Get the app running --- ish * Get NextJS working * Remove `node:` * Get more tests passing in unit directory * Update FailBot test to use nock * Update test.yml * Update Dockerfile * tests/content fixes * Update page.js * Update build-changelog.js * updating tests/routing * Update orphan-tests.js * updating tests/rendering * Update .eslintrc.js * Update .eslintrc.js * Install jest/globals * "linting" tests * staging update to server.mjs * Change '.github/allowed-actions.js' to a ESM export * Lint * Fixes for the main package.json * Move Jest to be last in the npm test command so we can pass args * Just use 'npm run lint' in the npm test command * update algolia label script * update openapi script * update require on openapi * Update enterprise-algolia-label.js * forgot JSON.parse * Update lunr-search-index.js * Always explicitly include process.cwd() for JSON file reads pathed from project root * update graphql/update-files.js script * Update other npm scripts using jest to pass ESM NODE_OPTIONS * Update check-for-enterprise-issues-by-label.js for ESM * Update create-enterprise-issue.js for ESM * Import jest global for browser tests * Convert 'script/deploy' to ESM Co-authored-by: Grace Park <gracepark@github.com> Co-authored-by: James M. Greene <jamesmgreene@github.com>
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
import { fileURLToPath } from 'url'
|
|
import path from 'path'
|
|
import fs from 'fs'
|
|
import { chain, get, groupBy } from 'lodash-es'
|
|
import allVersions from '../all-versions.js'
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
const schemasPath = path.join(__dirname, 'static/decorated')
|
|
export const operations = {}
|
|
fs.readdirSync(schemasPath)
|
|
.forEach(filename => {
|
|
const key = filename.replace('.json', '')
|
|
const value = JSON.parse(fs.readFileSync(path.join(schemasPath, filename)))
|
|
operations[key] = value
|
|
})
|
|
const allVersionKeys = Object.keys(allVersions)
|
|
|
|
let allCategories = []
|
|
allVersionKeys.forEach(currentVersion => {
|
|
// Translate the versions from the openapi to versions used in the docs
|
|
const openApiVersion = allVersions[currentVersion].openApiVersionName
|
|
|
|
// Check that the openApiVersion is configured in OpenAPI
|
|
if (!operations[openApiVersion]) return
|
|
|
|
operations[currentVersion] = operations[openApiVersion]
|
|
delete operations[openApiVersion]
|
|
|
|
// This list is generated for use in the tests,
|
|
// so we can verify that the names of the markdown files
|
|
// in content/rest/reference/*.md are congruous with the
|
|
// set of REST resource names like activity, gists, repos, etc.
|
|
allCategories = allCategories.concat(chain(operations[currentVersion]).map('category').sort().uniq().value())
|
|
|
|
// Attach convenience properties to each operation that can't easily be created in Liquid
|
|
operations[currentVersion].forEach(operation => {
|
|
operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required)
|
|
})
|
|
})
|
|
|
|
// Get the unique set of categories
|
|
const categories = [...new Set(allCategories)]
|
|
|
|
// This is a collection of operations that have `enabledForGitHubApps = true`
|
|
// It's grouped by resource title to make rendering easier
|
|
const operationsEnabledForGitHubApps = allVersionKeys.reduce((acc, currentVersion) => {
|
|
acc[currentVersion] = chain(operations[currentVersion] || [])
|
|
.filter(operation => operation['x-github'].enabledForGitHubApps)
|
|
.orderBy('category')
|
|
.value()
|
|
acc[currentVersion] = groupBy(acc[currentVersion], 'category')
|
|
return acc
|
|
}, {})
|
|
|
|
export default {
|
|
categories,
|
|
operations,
|
|
operationsEnabledForGitHubApps
|
|
}
|