Skip to content

Commit af7d3eb

Browse files
authored
repo sync
2 parents ae33fe9 + f22a82f commit af7d3eb

4 files changed

Lines changed: 30 additions & 28 deletions

File tree

lib/all-versions.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ const plans = [
1212
planTitle: 'Free, Pro, and Team',
1313
releases: [latestNonNumberedRelease],
1414
latestRelease: latestNonNumberedRelease,
15-
nonEnterpriseDefault: true // permanent way to refer to this plan if the name changes
15+
nonEnterpriseDefault: true, // permanent way to refer to this plan if the name changes
16+
openApiBaseName: 'dotcom'
1617
},
1718
{
1819
plan: 'enterprise-server',
1920
planTitle: 'Enterprise Server',
2021
releases: enterpriseServerReleases.supported,
2122
latestRelease: enterpriseServerReleases.latest,
22-
hasNumberedReleases: true
23+
hasNumberedReleases: true,
24+
openApiBaseName: ''
2325
}
2426
]
2527

@@ -35,7 +37,8 @@ plans.forEach(planObj => {
3537
version,
3638
versionTitle: planObj.hasNumberedReleases ? `${planObj.planTitle} ${release}` : planObj.planTitle,
3739
latestVersion: `${planObj.plan}${versionDelimiter}${planObj.latestRelease}`,
38-
currentRelease: release
40+
currentRelease: release,
41+
openApiVersionName: planObj.hasNumberedReleases ? `${planObj.openApiBaseName}${release}` : planObj.openApiBaseName
3942
}
4043

4144
allVersions[version] = Object.assign(versionObj, planObj)

lib/rest.js

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,34 @@
1-
const { chain, get, union, flatten, groupBy } = require('lodash')
2-
const { supported } = require('./enterprise-server-releases')
1+
const { chain, get, groupBy } = require('lodash')
32
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)
65

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())
1718

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 => {
2121
operation.hasRequiredPreviews = get(operation, 'x-github.previews', []).some(preview => preview.required)
2222
})
2323
})
2424

25+
// Get the unique set of categories
26+
const categories = [...new Set(allCategories)]
27+
2528
// This is a collection of operations that have `enabledForGitHubApps = true`
2629
// 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] || [])
2932
.filter(operation => operation['x-github'].enabledForGitHubApps)
3033
.orderBy('category')
3134
.value()

middleware/contextualizers/rest.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
const rest = require('../../lib/rest')
22
const { getVersionedPathWithLanguage } = require('../../lib/path-utils')
3-
const { getOldVersionFromNewVersion } = require('../../lib/old-versions-utils')
43

54
module.exports = async function (req, res, next) {
65
req.context.rest = rest
76

8-
// TODO need to update this to the new versions in coordination with the updater scripts
9-
const currentOldVersion = getOldVersionFromNewVersion(req.context.currentVersion)
10-
117
// link to include in `Works with GitHub Apps` notes
128
// e.g. /ja/rest/reference/apps or /en/enterprise/2.20/user/rest/reference/apps
139
req.context.restGitHubAppsLink = getVersionedPathWithLanguage(
@@ -28,7 +24,7 @@ module.exports = async function (req, res, next) {
2824
// ignore empty strings or bare `/`
2925
if (!category || category.length < 2) return next()
3026

31-
const operationsForCurrentProduct = req.context.rest.operations[currentOldVersion] || []
27+
const operationsForCurrentProduct = req.context.rest.operations[req.context.currentVersion] || []
3228

3329
// find all operations with a category matching the current path
3430
req.context.currentRestOperations = operationsForCurrentProduct.filter(operation => operation.category === category)

tests/links-and-images/developer-links-and-images.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('page rendering', () => {
8888
languageCode
8989
)
9090

91-
context.operationsForCurrentProduct = context.rest.operations[currentOldVersion] || []
91+
context.operationsForCurrentProduct = context.rest.operations[pageVersion] || []
9292

9393
if (relevantPermalink.href.includes('rest/reference/')) {
9494
const docsPath = relevantPermalink.href

0 commit comments

Comments
 (0)