Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 23 additions & 14 deletions pr-checks/changenotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ function getChangenotes(): ChangenoteFile[] {
});
}

/**
* Populates the '[UNRELEASED]' section of CHANGELOG.md with the contents
* of the changenotes in {@link CHANGENOTES_DIR} and then deletes those changenotes.
* @param contents The contents of CHANGELOG.md
* @returns The updated contents of CHANGELOG.md
*/
export function transferChangenotesToChangelog(contents: string): string {
const changenotes = getChangenotes();
const changenoteBodies = changenotes.map((c) => c.content.trim());
const changenotePaths = changenotes.map((c) => c.absolutePath);

const changelog = parseChangelog(contents);
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
const updatedChangelog = renderChangelog(changelog);

for (const p of changenotePaths) {
fs.unlinkSync(p);
}
Comment thread
mario-campos marked this conversation as resolved.

return updatedChangelog;
}

const entryPoint = process.argv[1];
if (entryPoint && import.meta.url === pathToFileURL(entryPoint).href) {
try {
Expand Down Expand Up @@ -91,26 +113,13 @@ function usage(): ExitCode {

function assemble(): ExitCode {
try {
const changenotes = getChangenotes();
const changenoteBodies = changenotes.map((c) => c.content);
const changenotePaths = changenotes.map((c) => c.absolutePath);

withChangelog((contents) => {
const changelog = parseChangelog(contents);
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
return renderChangelog(changelog);
return transferChangenotesToChangelog(contents);
}, {});

// Delete changenotes only after successful processing.
for (const p of changenotePaths) {
fs.unlinkSync(p);
}

return ExitCode.Success;
} catch (e) {
console.error("Failed to assemble changenotes to 'CHANGELOG.md'", e);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Odd

return ExitCode.Failure;
}

Expand Down
15 changes: 12 additions & 3 deletions pr-checks/update-release-branch.ts
Comment thread
mario-campos marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ import { parseArgs } from "node:util";

import { type ApiClient, getApiClient } from "./api-client";
import * as changelog from "./changelog";
import { DryRunOption, REPO_ROOT } from "./config";
import { transferChangenotesToChangelog } from "./changenotes";
import {
CHANGELOG_FILE,
CHANGENOTES_DIR,
DryRunOption,
REPO_ROOT,
} from "./config";
import {
getCurrentVersion,
replaceVersionInPackageJson,
Expand Down Expand Up @@ -693,11 +699,14 @@ export async function prepareNewBranch(

console.log("Updating changelog");
changelog.withChangelog(
(contents) => changelog.setVersionAndDate(version, contents),
(contents) => {
const populatedContents = transferChangenotesToChangelog(contents);
return changelog.setVersionAndDate(version, populatedContents);
},
{ ...options, initChangelog: true },
);

runGit(["add", "CHANGELOG.md"], {
runGit(["add", CHANGELOG_FILE, CHANGENOTES_DIR], {
dryRun: options.dryRun,
});
runGit(["commit", "-m", `Update changelog for v${version}`], {
Expand Down
Loading