From 39528452cf2bd96d334804b15d2b36bd8bc7d2c2 Mon Sep 17 00:00:00 2001 From: Henry Mercer Date: Mon, 2 Nov 2026 17:40:43 +0000 Subject: [PATCH] Remove unused `updateChangelog` from `bundle-changelog.ts` Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- pr-checks/bundle-changelog.test.ts | 62 ------------------------------ pr-checks/bundle-changelog.ts | 44 --------------------- 2 files changed, 106 deletions(-) diff --git a/pr-checks/bundle-changelog.test.ts b/pr-checks/bundle-changelog.test.ts index 2aa90b35e..448851507 100644 --- a/pr-checks/bundle-changelog.test.ts +++ b/pr-checks/bundle-changelog.test.ts @@ -15,13 +15,7 @@ import { getPRNumber, getPRUrl, PR_URL_ENV_VAR, - updateChangelog, } from "./bundle-changelog"; -import { - EMPTY_CHANGELOG, - NO_CHANGES_STR, - UNRELEASED_PLACEHOLDER, -} from "./changelog"; import { isValidChangenoteContent } from "./changelog/validate"; let testDir: string; @@ -87,62 +81,6 @@ describe("getPRNumber", async () => { }); }); -const testChangelog = `${EMPTY_CHANGELOG.trimEnd()} - -## 4.23.7 - -- Other change - -## 4.23.6 - -${NO_CHANGES_STR}`; - -const expectedChangelog = `# CodeQL Action Changelog - -## ${UNRELEASED_PLACEHOLDER} - -- Update default CodeQL bundle version to - -## 4.23.7 - -- Other change - -## 4.23.6 - -${NO_CHANGES_STR}`; - -describe("updateChangelog", async () => { - await it("removes `NO_CHANGES_STR` if present in [UNRELEASED] section", async () => { - const result = updateChangelog(EMPTY_CHANGELOG, ""); - assert.ok(!result.includes(NO_CHANGES_STR)); - }); - - await it("doesn't remove `NO_CHANGES_STR` if present in versioned section", async () => { - const result = updateChangelog( - EMPTY_CHANGELOG.replace(UNRELEASED_PLACEHOLDER, "1.2.3"), - "", - ); - assert.ok(result.includes(NO_CHANGES_STR)); - }); - - await it("throws if there are no sections", async () => { - assert.throws(() => { - updateChangelog( - "# CodeQL Action Changelog", - "- Update default CodeQL bundle version to", - ); - }); - }); - - await it("adds note at the end of the first section", async () => { - const result = updateChangelog( - testChangelog, - "- Update default CodeQL bundle version to", - ); - assert.deepEqual(result, expectedChangelog); - }); -}); - describe("getChangenote", async () => { await it("returns a note linking to the bundle release and the PR", async () => { assert.equal( diff --git a/pr-checks/bundle-changelog.ts b/pr-checks/bundle-changelog.ts index d2f5aae69..8019c7090 100755 --- a/pr-checks/bundle-changelog.ts +++ b/pr-checks/bundle-changelog.ts @@ -7,11 +7,6 @@ import * as fs from "node:fs"; import * as path from "node:path"; -import { - parseChangelog, - renderChangelog, - UNRELEASED_PLACEHOLDER, -} from "./changelog"; import { CHANGENOTES_DIR, CLI_BUNDLE_RELEASE_URL_PREFIX } from "./config"; import { getErrorMessage } from "./util"; @@ -58,45 +53,6 @@ export function getPRNumber(prUrl: string) { return prNumber; } -/** - * Updates `changelog` by adding `changelogNote` to the first section. - * - * @param contents The existing changelog contents. - * @param changelogNote The note to add to the first section. - */ -export function updateChangelog(contents: string, changelogNote: string) { - // If the "[UNRELEASED]" section starts with "no user facing changes", remove that line. - contents = contents.replace( - `## ${UNRELEASED_PLACEHOLDER}\n\nNo user facing changes.`, - `## ${UNRELEASED_PLACEHOLDER}\n`, - ); - - const changelog = parseChangelog(contents); - - if (changelog.sections.length === 0) { - throw new Error("The changelog contains no existing sections."); - } - - // Add the changelog note to the bottom of the first section. - const firstSection = changelog.sections[0]; - const lastLine = firstSection.bodyLines.pop(); - - if (lastLine !== undefined && lastLine.trim() !== "") { - // We expect the last line to be empty. If it isn't for some reason, - // add it back. - firstSection.bodyLines.push(lastLine); - } - - firstSection.bodyLines.push(changelogNote); - - // If the last line is empty as expected, then add it back in after the new note. - if (lastLine?.trim() === "") { - firstSection.bodyLines.push(lastLine); - } - - return renderChangelog(changelog); -} - /** * Returns the contents of the changenote file for an update to the default * CodeQL CLI bundle.