Migrate unreleased changes in changelog (#10853)

When updating the changelog for a release candidate, any unreleased
changes are now migrated to the release header.

Generally we don't make a habit of adding changes to the changelog
prior to creating a release candidate, but if any are there we
certainly don't want them duplicated.
feature/default_network_editable
Mark Stacey 4 years ago committed by GitHub
parent a814f8ee75
commit e77aa0b7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      development/lib/changelog/changelog.js
  2. 10
      development/lib/changelog/updateChangelog.js

@ -233,6 +233,36 @@ class Changelog {
}
}
/**
* Migrate all unreleased changes to a release section.
*
* Changes are migrated in their existing categories, and placed above any
* pre-existing changes in that category.
*
* @param {Version} version - The release version to migrate unreleased
* changes to.
*/
migrateUnreleasedChangesToRelease(version) {
const releaseChanges = this._changes[version];
if (!releaseChanges) {
throw new Error(`Specified release version does not exist: '${version}'`);
}
const unreleasedChanges = this._changes[unreleased];
for (const category of Object.keys(unreleasedChanges)) {
if (releaseChanges[category]) {
releaseChanges[category] = [
...unreleasedChanges[category],
...releaseChanges[category],
];
} else {
releaseChanges[category] = unreleasedChanges[category];
}
}
this._changes[unreleased] = {};
}
/**
* Gets the metadata for all releases.
* @returns {Array<ReleaseMetadata>} The metadata for each release.

@ -127,7 +127,11 @@ async function updateChangelog({
({ prNumber }) => !loggedPrNumbers.includes(prNumber),
);
if (newCommits.length === 0) {
const hasUnreleasedChanges = changelog.getUnreleasedChanges().length !== 0;
if (
newCommits.length === 0 &&
(!isReleaseCandidate || hasUnreleasedChanges)
) {
return undefined;
}
@ -141,6 +145,10 @@ async function updateChangelog({
changelog.addRelease({ currentVersion });
}
if (isReleaseCandidate && hasUnreleasedChanges) {
changelog.migrateUnreleasedChangesToRelease(currentVersion);
}
const newChangeEntries = newCommits.map(({ prNumber, description }) => {
if (prNumber) {
const prefix = `[#${prNumber}](${repoUrl}/pull/${prNumber})`;

Loading…
Cancel
Save