From 5b5a4f6fd99e944008dedf39d5c6a1d6b3fa24cc Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Thu, 1 Apr 2021 21:09:14 -0230 Subject: [PATCH] Add release header when updating changelog (#10794) The changelog update script now adds a release header if it doesn't find one already that matches the current release candidate version. --- development/auto-changelog.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/development/auto-changelog.js b/development/auto-changelog.js index 4a6c42bca..7e5d719ef 100755 --- a/development/auto-changelog.js +++ b/development/auto-changelog.js @@ -80,15 +80,22 @@ async function main() { `${versionHeader}$|${versionHeader}\\s` : currentDevelopBranchHeader; - const releaseHeaderIndex = changelogLines.findIndex((line) => + let releaseHeaderIndex = changelogLines.findIndex((line) => line.match(new RegExp(currentReleaseHeaderPattern, 'u')), ); if (releaseHeaderIndex === -1) { - throw new Error( - `Failed to find release header '${ - isReleaseCandidate ? versionHeader : currentDevelopBranchHeader - }'`, + if (!isReleaseCandidate) { + throw new Error( + `Failed to find release header '${currentDevelopBranchHeader}'`, + ); + } + + // Add release header if not found + const firstReleaseHeaderIndex = changelogLines.findIndex((line) => + line.match(/## \d+\.\d+\.\d+/u), ); + changelogLines.splice(firstReleaseHeaderIndex, 0, versionHeader, ''); + releaseHeaderIndex = firstReleaseHeaderIndex; } const prNumbersWithChangelogEntries = [];