From ef9157b37a9d813fb5f05ddb657225fade76df38 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 21 Nov 2023 12:31:40 +0000 Subject: [PATCH] Fix `Ingest upstream changes` for downstreams with missing sections Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- scripts/release/merge-release-notes.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/scripts/release/merge-release-notes.js b/scripts/release/merge-release-notes.js index aa8d0c2f0..bd2cf3504 100755 --- a/scripts/release/merge-release-notes.js +++ b/scripts/release/merge-release-notes.js @@ -36,12 +36,12 @@ const main = async ({ github, releaseId, dependencies }) => { const release = await getRelease(github, dependency); for (const line of release.body.split("\n")) { if (line.startsWith(HEADING_PREFIX)) { - heading = line; + heading = line.trim(); sections.set(heading, []); continue; } if (heading && line) { - sections.get(heading).push(line); + sections.get(heading).push(line.trim()); } } } @@ -60,10 +60,14 @@ const main = async ({ github, releaseId, dependencies }) => { const output = []; for (const line of [...release.body.split("\n"), null]) { if (line === null || line.startsWith(HEADING_PREFIX)) { - while (heading && headings[0] !== heading && sections.has(headings[0])) { + // If we have a heading, and it's not the first in the list of pending headings, output the section. + // If we're processing the last line (null) then output all remaining sections. + while (headings.length > 0 && (line === null || (heading && headings[0] !== heading))) { const heading = headings.shift(); - output.push(heading); - output.push(...sections.get(heading)); + if (sections.has(heading)) { + output.push(heading); + output.push(...sections.get(heading)); + } } if (heading && sections.has(heading)) {