Skip to content

Commit dde5027

Browse files
committed
Hoist core of changenotes.mts assemble into own function
1 parent 2c8d410 commit dde5027

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

‎pr-checks/changenotes.mts‎

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,28 @@ function getChangenotes(): ChangenoteFile[] {
5050
});
5151
}
5252

53+
/**
54+
* Populates the '[UNRELEASED]' section of CHANGELOG.md with the contents
55+
* of the changenotes in {@link CHANGENOTES_DIR} and then deletes those changenotes.
56+
* @param contents The contents of CHANGELOG.md
57+
* @returns The updated contents of CHANGELOG.md
58+
*/
59+
export function transferChangenotesToChangelog(contents: string): string {
60+
const changenotes = getChangenotes();
61+
const changenoteBodies = changenotes.map((c) => c.content);
62+
const changenotePaths = changenotes.map((c) => c.absolutePath);
63+
64+
const changelog = parseChangelog(contents);
65+
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
66+
const updatedChangelog = renderChangelog(changelog);
67+
68+
for (const p of changenotePaths) {
69+
fs.unlinkSync(p);
70+
}
71+
72+
return updatedChangelog;
73+
}
74+
5375
const entryPoint = process.argv[1];
5476
if (entryPoint && import.meta.url === pathToFileURL(entryPoint).href) {
5577
try {
@@ -91,26 +113,13 @@ function usage(): ExitCode {
91113

92114
function assemble(): ExitCode {
93115
try {
94-
const changenotes = getChangenotes();
95-
const changenoteBodies = changenotes.map((c) => c.content);
96-
const changenotePaths = changenotes.map((c) => c.absolutePath);
97-
98116
withChangelog((contents) => {
99-
const changelog = parseChangelog(contents);
100-
addBodyLinesToUnreleasedSection(changelog, changenoteBodies);
101-
return renderChangelog(changelog);
117+
return transferChangenotesToChangelog(contents);
102118
}, {});
103-
104-
// Delete changenotes only after successful processing.
105-
for (const p of changenotePaths) {
106-
fs.unlinkSync(p);
107-
}
108-
109119
return ExitCode.Success;
110120
} catch (e) {
111121
console.error("Failed to assemble changenotes to 'CHANGELOG.md'", e);
112122
}
113-
114123
return ExitCode.Failure;
115124
}
116125

0 commit comments

Comments
 (0)