1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02:00

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.
This commit is contained in:
Mark Stacey 2021-04-08 17:53:00 -02:30 committed by GitHub
parent a814f8ee75
commit e77aa0b7b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -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.

View File

@ -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})`;