* remove FEATURE_NEW_VERSIONS from feature-flags.json * remove process.env.FEATURE_NEW_VERSIONS from include files * remove process.env.FEATURE_NEW_VERSIONS from lib files * remove process.env.FEATURE_NEW_VERSIONS from middleware files * remove process.env.FEATURE_NEW_VERSIONS from script files * remove process.env.FEATURE_NEW_VERSIONS from test files * update test fixtures to use new versions as canonical fixtures
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
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(
|
|
'/developers/apps',
|
|
req.context.currentVersion,
|
|
req.context.currentLanguage
|
|
)
|
|
|
|
// ignore requests to non-REST reference paths
|
|
if (!req.path.includes('rest/reference')) return next()
|
|
|
|
// e.g. the `activity` from `/en/rest/reference/activity#events`
|
|
const category = req.path
|
|
.split('rest/reference')[1]
|
|
.replace(/^\//, '') // remove leading slash
|
|
.split('/')[0]
|
|
|
|
// ignore empty strings or bare `/`
|
|
if (!category || category.length < 2) return next()
|
|
|
|
const operationsForCurrentProduct = req.context.rest.operations[currentOldVersion] || []
|
|
|
|
// find all operations with a category matching the current path
|
|
req.context.currentRestOperations = operationsForCurrentProduct.filter(operation => operation.category === category)
|
|
|
|
return next()
|
|
}
|