MCPcopy Index your code
hub / github.com/github/docs / getReleaseNotes

Function getReleaseNotes

middleware/contextualizers/get-release-notes.js:8–64  ·  view source on GitHub ↗
(prefix, langCode)

Source from the content-addressed store, hash-verified

6const VALID_PREFIXES = new Set(['enterprise-server', 'github-ae'])
7
8export function getReleaseNotes(prefix, langCode) {
9 if (!VALID_PREFIXES.has(prefix)) {
10 throw new Error(
11 `'${prefix}' is not a valid prefix for this function. Must be one of ${Array.from(
12 VALID_PREFIXES
13 )}`
14 )
15 }
16 // Use English as the foundation, then we'll try to load each individual
17 // data/release-notes/**/*.yml file from the translation.
18 // If the language is 'en', don't even bother merging.
19 const releaseNotes = getDeepDataByLanguage(`release-notes.${prefix}`, 'en')
20 if (langCode === 'en') {
21 // Exit early because nothing special needs to be done.
22 return releaseNotes
23 }
24
25 // The reason we're doing this is because we can't trust
26 // getDeepDataByLanguage() in the translations because it depends on
27 // loading in all possible files in the directory. Translations often
28 // don't delete files, so we use the English data as a guide for which
29 // data files to bother reading.
30
31 // We start with the English release notes and iterate over the keys,
32 // then for each nested key, try to pull it from the translation.
33 // If we encounter valid sections, use it. If not valid,
34 // use the English ones.
35 // The output of `getDeepDataByLanguage()` is a mutatable object
36 // from a memoize cache, so don't mutate it to avoid confusing bugs.
37 const translatedReleaseNotes = {}
38
39 // Now, let's iterated over all nested keys and for each one load in the
40 // translated releases.
41 for (const [majorVersion, releases] of Object.entries(releaseNotes)) {
42 // Major version is things like '3-7'
43 translatedReleaseNotes[majorVersion] = {}
44 for (const minorVersion of Object.keys(releases)) {
45 // Minor version is things like '0-rc1' or '3'
46 const data = getDataByLanguage(
47 `release-notes.${prefix}.${majorVersion}.${minorVersion}`,
48 langCode
49 )
50 // A simple but powerful validation. If the `sections:` thing
51 // is incorrectly translated so it's no longer an array, then we
52 // don't pick this up from the translation.
53 const validSections = Object.values(data.sections).every((sectionValue) =>
54 Array.isArray(sectionValue)
55 )
56 if (validSections) {
57 translatedReleaseNotes[majorVersion][minorVersion] = data
58 } else {
59 translatedReleaseNotes[majorVersion][minorVersion] = releases[minorVersion]
60 }
61 }
62 }
63 return translatedReleaseNotes
64}

Callers 2

ghesReleaseNotesContextFunction · 0.90
ghaeReleaseNotesContextFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected