|
1 | | -const { chain, get, union, flatten, groupBy } = require('lodash') |
2 | | -const { supported } = require('./enterprise-server-releases') |
| 1 | +const { chain, get, groupBy } = require('lodash') |
3 | 2 | const operations = require('@github/rest-api-operations') |
4 | | -const { getOldVersionFromNewVersion } = require('./old-versions-utils') |
5 | | -const allVersions = Object.keys(require('./all-versions')) |
| 3 | +const allVersions = require('./all-versions') |
| 4 | +const allVersionKeys = Object.keys(allVersions) |
6 | 5 |
|
7 | | -// This list is generated for use in the tests, |
8 | | -// so we can verify that the names of the markdown files |
9 | | -// in content/rest/reference/*.md are congruous with the |
10 | | -// set of REST resource names like activity, gists, repos, etc. |
11 | | -function getCategories (operations) { |
12 | | - return chain(operations).map('category').sort().uniq().value() |
13 | | -} |
14 | | -const dotcomCategories = getCategories(operations.dotcom) |
15 | | -const enterpriseCategories = flatten(supported.map(v => getCategories(operations[v]))) |
16 | | -const categories = union(dotcomCategories, enterpriseCategories) |
| 6 | +let allCategories = [] |
| 7 | +allVersionKeys.forEach(currentVersion => { |
| 8 | + // Translate the versions from the openapi to versions used in the docs |
| 9 | + const openApiVersion = allVersions[currentVersion].openApiVersionName |
| 10 | + operations[currentVersion] = operations[openApiVersion] |
| 11 | + delete operations[openApiVersion] |
| 12 | + |
| 13 | + // This list is generated for use in the tests, |
| 14 | + // so we can verify that the names of the markdown files |
| 15 | + // in content/rest/reference/*.md are congruous with the |
| 16 | + // set of REST resource names like activity, gists, repos, etc. |
| 17 | + allCategories = allCategories.concat(chain(operations[currentVersion]).map('category').sort().uniq().value()) |
17 | 18 |
|
18 | | -// Attach convenience properties to each operation that can't easily be created in Liquid |
19 | | -allVersions.forEach(currentVersion => { |
20 | | - operations[getOldVersionFromNewVersion(currentVersion)].forEach(operation => { |
| 19 | + // Attach convenience properties to each operation that can't easily be created in Liquid |
| 20 | + operations[currentVersion].forEach(operation => { |
21 | 21 | operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required) |
22 | 22 | }) |
23 | 23 | }) |
24 | 24 |
|
| 25 | +// Get the unique set of categories |
| 26 | +const categories = [...new Set(allCategories)] |
| 27 | + |
25 | 28 | // This is a collection of operations that have `enabledForGitHubApps = true` |
26 | 29 | // It's grouped by resource title to make rendering easier |
27 | | -const operationsEnabledForGitHubApps = allVersions.reduce((acc, currentVersion) => { |
28 | | - acc[currentVersion] = chain(operations[getOldVersionFromNewVersion(currentVersion)] || []) |
| 30 | +const operationsEnabledForGitHubApps = allVersionKeys.reduce((acc, currentVersion) => { |
| 31 | + acc[currentVersion] = chain(operations[currentVersion] || []) |
29 | 32 | .filter(operation => operation['x-github'].enabledForGitHubApps) |
30 | 33 | .orderBy('category') |
31 | 34 | .value() |
|
0 commit comments