зеркало из https://github.com/github/docs.git
translate openapi versioning (#16202)
This commit is contained in:
Родитель
d743ff9512
Коммит
f22a82fcfb
|
@ -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)
|
||||
|
|
41
lib/rest.js
41
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()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче