Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github#29190 from github/repo-sync
Browse files Browse the repository at this point in the history
Repo sync
docs-bot authored Oct 16, 2023
2 parents 3d50515 + 753ebc2 commit fe9970b
Showing 2 changed files with 33 additions and 10 deletions.
39 changes: 31 additions & 8 deletions components/context/MainContext.tsx
Original file line number Diff line number Diff line change
@@ -15,17 +15,40 @@ type VersionItem = {
// free-pro-team@latest, enterprise-cloud@latest, enterprise-server@3.3 ...
version: string
versionTitle: string
currentRelease: string
latestVersion: string
shortName: string
// api.github.com, ghec, ghes-3.3, github.ae
openApiVersionName: string
// api.github.com, ghec, ghes-, github.ae
openApiBaseName: string
isGHES?: boolean
apiVersions: string[]
latestApiVersion: string
}

// This reflects what gets exported from `all-versions.js` in the
// `allVersions` object.
// It's necessary for TypeScript, but we don't need to write down
// every possible key that might be present because we don't need it
// for rendering.
type FullVersionItem = VersionItem & {
shortName: string
}

function minimalAllVersions(
allVersions: Record<string, FullVersionItem>,
): Record<string, VersionItem> {
const all: Record<string, VersionItem> = {}
for (const [plan, info] of Object.entries(allVersions)) {
all[plan] = {
version: info.version,
versionTitle: info.versionTitle,
apiVersions: info.apiVersions,
latestApiVersion: info.latestApiVersion,
}
// Deal with keys that are optional. It's preferred to omit
// booleans if they're false anyway.
if (info.shortName === 'ghes') {
all[plan].isGHES = true
}
}
return all
}

export type ProductTreeNode = {
title: string
href: string
@@ -171,7 +194,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
'supported',
]),
enterpriseServerVersions: req.context.enterpriseServerVersions,
allVersions: req.context.allVersions,
allVersions: minimalAllVersions(req.context.allVersions),
currentVersion: req.context.currentVersion,
// This is a slimmed down version of `req.context.currentProductTree`
// that only has the minimal titles stuff needed for sidebars and
4 changes: 2 additions & 2 deletions src/rest/components/RestBanner.tsx
Original file line number Diff line number Diff line change
@@ -50,13 +50,13 @@ export const RestBanner = () => {
bannerText = t('rest.banner.api_versioned')
versionWithApiVersion = currentVersion
} else {
if (currentVersionObj.shortName === 'ghes') {
if (currentVersionObj.isGHES) {
// If this is a GHES release with no REST versions,
// find out if any GHES releases contain REST versioning yet.
const firstGhesReleaseWithApiVersions = Object.values(allVersions)
.reverse()
.find((v) => {
return v.shortName === 'ghes' && v.apiVersions.length
return v.isGHES && v.apiVersions.length
})

if (firstGhesReleaseWithApiVersions) {

0 comments on commit fe9970b

Please sign in to comment.