(req, res, next)
| 4 | import { getReleaseNotes } from './get-release-notes.js' |
| 5 | |
| 6 | export default async function ghesReleaseNotesContext(req, res, next) { |
| 7 | if (!(req.pagePath.endsWith('/release-notes') || req.pagePath.endsWith('/admin'))) return next() |
| 8 | const [requestedPlan, requestedRelease] = req.context.currentVersion.split('@') |
| 9 | if (requestedPlan !== 'enterprise-server') return next() |
| 10 | |
| 11 | const ghesReleaseNotes = getReleaseNotes('enterprise-server', req.language) |
| 12 | |
| 13 | // If the requested GHES release isn't found in data/release-notes/enterprise-server/*, |
| 14 | // and it IS a valid GHES release, try being helpful and redirecting to the old location. |
| 15 | // Otherwise, 404. |
| 16 | if (!Object.keys(ghesReleaseNotes).includes(requestedRelease.replace(/\./, '-'))) { |
| 17 | return all.includes(requestedRelease) |
| 18 | ? res.redirect(`https://enterprise.github.com/releases/${requestedRelease}.0/notes`) |
| 19 | : next() |
| 20 | } |
| 21 | |
| 22 | // Returns [{version, patches: [{version, patchVersion, intro, date, sections: { features: [], bugs: []...}} ]}] |
| 23 | req.context.ghesReleases = formatReleases(ghesReleaseNotes) |
| 24 | |
| 25 | // Find the notes for the current release only |
| 26 | const currentReleaseNotes = req.context.ghesReleases.find( |
| 27 | (r) => r.version === requestedRelease |
| 28 | ).patches |
| 29 | |
| 30 | // Run the current release notes through the markdown rendering pipeline. |
| 31 | // Returns the current release's patches array: [{version, patchVersion, intro, date, sections}] |
| 32 | req.context.ghesReleaseNotes = await executeWithFallback( |
| 33 | req.context, |
| 34 | () => renderPatchNotes(currentReleaseNotes, req.context), |
| 35 | (enContext) => { |
| 36 | // Something in the release notes ultimately caused a Liquid |
| 37 | // rendering error. Let's start over and gather the English release |
| 38 | // notes instead. |
| 39 | const ghesReleaseNotes = getReleaseNotes('enterprise-server', 'en') |
| 40 | enContext.ghesReleases = formatReleases(ghesReleaseNotes) |
| 41 | const currentReleaseNotes = enContext.ghesReleases.find( |
| 42 | (r) => r.version === requestedRelease |
| 43 | ).patches |
| 44 | return renderPatchNotes(currentReleaseNotes, enContext) |
| 45 | } |
| 46 | ) |
| 47 | |
| 48 | // GHES release notes on docs started with 2.20 but older release notes exist on enterprise.github.com. |
| 49 | // So we want to use _all_ GHES versions when calculating next and previous releases. |
| 50 | req.context.latestPatch = req.context.ghesReleaseNotes[0].version |
| 51 | req.context.latestRelease = all[0] |
| 52 | |
| 53 | // Add convenience props for "Supported releases" section on GHES Admin landing page (NOT release notes). |
| 54 | req.context.ghesReleases.forEach((release) => { |
| 55 | release.firstPreviousRelease = all[all.findIndex((v) => v === release.version) + 1] |
| 56 | release.secondPreviousRelease = |
| 57 | all[all.findIndex((v) => v === release.firstPreviousRelease) + 1] |
| 58 | }) |
| 59 | |
| 60 | return next() |
| 61 | } |
nothing calls this directly
no test coverage detected