forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest.js
40 lines (36 loc) · 1.74 KB
/
rest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
const { chain, get, union, flatten, groupBy } = require('lodash')
const { supported } = require('./enterprise-server-releases')
const operations = require('@github/rest-api-operations')
const { getOldVersionFromNewVersion } = require('./old-versions-utils')
const allVersions = Object.keys(require('./all-versions'))
// 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.
function getCategories (operations) {
return chain(operations).map('category').sort().uniq().value()
}
const dotcomCategories = getCategories(operations.dotcom)
const enterpriseCategories = flatten(supported.map(v => getCategories(operations[v])))
const categories = union(dotcomCategories, enterpriseCategories)
// Attach convenience properties to each operation that can't easily be created in Liquid
allVersions.forEach(currentVersion => {
operations[getOldVersionFromNewVersion(currentVersion)].forEach(operation => {
operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required)
})
})
// This is a collection of operations that have `enabledForGitHubApps = true`
// It's grouped by resource title to make rendering easier
const operationsEnabledForGitHubApps = allVersions.reduce((acc, currentVersion) => {
acc[currentVersion] = chain(operations[getOldVersionFromNewVersion(currentVersion)] || [])
.filter(operation => operation['x-github'].enabledForGitHubApps)
.orderBy('category')
.value()
acc[currentVersion] = groupBy(acc[currentVersion], 'category')
return acc
}, {})
module.exports = {
categories,
operations,
operationsEnabledForGitHubApps
}