diff --git a/lib/all-versions.js b/lib/all-versions.js index 25cc47a8e8..e233a61e66 100644 --- a/lib/all-versions.js +++ b/lib/all-versions.js @@ -12,14 +12,16 @@ const plans = [ planTitle: 'Free, Pro, and Team', releases: [latestNonNumberedRelease], latestRelease: latestNonNumberedRelease, - nonEnterpriseDefault: true // permanent way to refer to this plan if the name changes + nonEnterpriseDefault: true, // permanent way to refer to this plan if the name changes + openApiBaseName: 'dotcom' }, { plan: 'enterprise-server', planTitle: 'Enterprise Server', releases: enterpriseServerReleases.supported, latestRelease: enterpriseServerReleases.latest, - hasNumberedReleases: true + hasNumberedReleases: true, + openApiBaseName: '' } ] @@ -35,7 +37,8 @@ plans.forEach(planObj => { version, versionTitle: planObj.hasNumberedReleases ? `${planObj.planTitle} ${release}` : planObj.planTitle, latestVersion: `${planObj.plan}${versionDelimiter}${planObj.latestRelease}`, - currentRelease: release + currentRelease: release, + openApiVersionName: planObj.hasNumberedReleases ? `${planObj.openApiBaseName}${release}` : planObj.openApiBaseName } allVersions[version] = Object.assign(versionObj, planObj) diff --git a/lib/rest.js b/lib/rest.js index 923e6177aa..426f788678 100644 --- a/lib/rest.js +++ b/lib/rest.js @@ -1,31 +1,34 @@ -const { chain, get, union, flatten, groupBy } = require('lodash') -const { supported } = require('./enterprise-server-releases') +const { chain, get, groupBy } = require('lodash') const operations = require('@github/rest-api-operations') -const { getOldVersionFromNewVersion } = require('./old-versions-utils') -const allVersions = Object.keys(require('./all-versions')) +const allVersions = require('./all-versions') +const allVersionKeys = Object.keys(allVersions) -// 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) +let allCategories = [] +allVersionKeys.forEach(currentVersion => { + // Translate the versions from the openapi to versions used in the docs + const openApiVersion = allVersions[currentVersion].openApiVersionName + operations[currentVersion] = operations[openApiVersion] + delete operations[openApiVersion] -// Attach convenience properties to each operation that can't easily be created in Liquid -allVersions.forEach(currentVersion => { - operations[getOldVersionFromNewVersion(currentVersion)].forEach(operation => { + // 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 = allVersions.reduce((acc, currentVersion) => { - acc[currentVersion] = chain(operations[getOldVersionFromNewVersion(currentVersion)] || []) +const operationsEnabledForGitHubApps = allVersionKeys.reduce((acc, currentVersion) => { + acc[currentVersion] = chain(operations[currentVersion] || []) .filter(operation => operation['x-github'].enabledForGitHubApps) .orderBy('category') .value() diff --git a/middleware/contextualizers/rest.js b/middleware/contextualizers/rest.js index 68a518e960..0d63f8d93f 100644 --- a/middleware/contextualizers/rest.js +++ b/middleware/contextualizers/rest.js @@ -1,13 +1,9 @@ const rest = require('../../lib/rest') const { getVersionedPathWithLanguage } = require('../../lib/path-utils') -const { getOldVersionFromNewVersion } = require('../../lib/old-versions-utils') module.exports = async function (req, res, next) { req.context.rest = rest - // TODO need to update this to the new versions in coordination with the updater scripts - const currentOldVersion = getOldVersionFromNewVersion(req.context.currentVersion) - // link to include in `Works with GitHub Apps` notes // e.g. /ja/rest/reference/apps or /en/enterprise/2.20/user/rest/reference/apps req.context.restGitHubAppsLink = getVersionedPathWithLanguage( @@ -28,7 +24,7 @@ module.exports = async function (req, res, next) { // ignore empty strings or bare `/` if (!category || category.length < 2) return next() - const operationsForCurrentProduct = req.context.rest.operations[currentOldVersion] || [] + const operationsForCurrentProduct = req.context.rest.operations[req.context.currentVersion] || [] // find all operations with a category matching the current path req.context.currentRestOperations = operationsForCurrentProduct.filter(operation => operation.category === category) diff --git a/tests/links-and-images/developer-links-and-images.js b/tests/links-and-images/developer-links-and-images.js index 42c2a3af98..ddb327b3ee 100644 --- a/tests/links-and-images/developer-links-and-images.js +++ b/tests/links-and-images/developer-links-and-images.js @@ -88,7 +88,7 @@ describe('page rendering', () => { languageCode ) - context.operationsForCurrentProduct = context.rest.operations[currentOldVersion] || [] + context.operationsForCurrentProduct = context.rest.operations[pageVersion] || [] if (relevantPermalink.href.includes('rest/reference/')) { const docsPath = relevantPermalink.href