From d82cda1f5000b6e83b3de2aed4992843f07791e6 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 13:56:54 +0100 Subject: [PATCH 01/10] Add action to validate changelog diffs after merging --- .../check-merge-queue-changelogs/action.yml | 77 +++++++++++++++ .../check-changelog-diff.cjs | 94 +++++++++++++++++++ .github/workflows/lint-build-test.yml | 15 +++ 3 files changed, 186 insertions(+) create mode 100644 .github/actions/check-merge-queue-changelogs/action.yml create mode 100644 .github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml new file mode 100644 index 00000000000..4bd2a027dcc --- /dev/null +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -0,0 +1,77 @@ +name: Check merge queue changelogs +description: Check if the changelog was incorrectly merged in a merge queue + pull request. + +inputs: + head-ref: + description: The head ref of the pull request. + required: true + base-ref: + description: The base ref to compare against. + required: true + github-token: + description: The GitHub token to use for authentication. + required: true + +runs: + using: composite + steps: + - name: Checkout repository + uses: MetaMask/action-checkout-and-setup@v2 + with: + is-high-risk-environment: false + fetch-depth: 0 + + - name: Get pull request number + id: pr-number + uses: actions/github-script@v8 + env: + HEAD_REF: ${{ inputs.head-ref }} + with: + github-token: ${{ inputs.github-token }} + script: | + const { HEAD_REF } = process.env; + const match = HEAD_REF.match(/\/pr-([0-9]+)-/u); + if (!match) { + return core.setFailed(`Could not extract pull request number from head ref: "${HEAD_REF}".`); + } + + const number = parseInt(match[1], 10); + core.setOutput('pr-number', number); + + - name: Get pull request branch + id: pr-branch + shell: bash + env: + REPOSITORY: ${{ github.repository }} + PR_NUMBER: ${{ steps.pr-number.outputs.pr-number }} + run: | + BRANCH=$(gh api "/repos/${REPOSITORY}/pulls/${PR_NUMBER} --jq=.head.ref") + echo "pr-branch=$BRANCH" >> "$GITHUB_OUTPUT" + + - name: Check changelog changes + id: changelog-check + shell: bash + env: + REF: ${{ inputs.ref }} + BASE_REF: ${{ inputs.base-ref }} + PR_BRANCH: ${{ steps.pr-branch.outputs.pr-branch }} + REPOSITORY: ${{ github.repository }} + ACTION_PATH: ${{ github.action_path }} + run: | + set -euo pipefail + + UPDATED_CHANGELOGS=$(git diff origin/"$BASE_REF"...origin/"$PR_BRANCH" --name-only | grep -E 'CHANGELOG\.md$' || true) + if [ -n "$UPDATED_CHANGELOGS" ]; then + for FILE in $UPDATED_CHANGELOGS; do + git show origin/"$BASE_REF":"$FILE" > /tmp/base-changelog.md + git show origin/"$PR_BRANCH":"$FILE" > /tmp/pr-changelog.md + + node "${ACTION_PATH}/check-changelog-diff.cjs" \ + /tmp/base-changelog.md \ + /tmp/pr-changelog.md \ + "$FILE" + done + else + echo "No CHANGELOG.md files were modified in this PR." + fi diff --git a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs new file mode 100644 index 00000000000..d220ea30390 --- /dev/null +++ b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs @@ -0,0 +1,94 @@ +// This script checks that any new changelog entries added in a PR +// remain in the [Unreleased] section after the PR is merged. + +const fs = require('fs'); + +if (process.argv.length < 5) { + console.error( + 'Usage: tsx check-changelog-diff.mts ', + ); + + // eslint-disable-next-line n/no-process-exit + process.exit(1); +} + +/* eslint-disable n/no-sync */ +const baseContent = fs.readFileSync(process.argv[2], 'utf8'); +const prContent = fs.readFileSync(process.argv[3], 'utf8'); +const mergedContent = fs.readFileSync(process.argv[4], 'utf8'); +/* eslint-enable n/no-sync */ + +/** + * Extract the "[Unreleased]" section from the changelog content. + * + * This doesn't actually parse the Markdown, it just looks for the section + * header and collects lines until the next section header. + * + * @param {string} content - The changelog content. + * @returns {Set} The lines in the "[Unreleased]" section as a + * {@link Set}. + */ +function getUnreleasedSection(content) { + const lines = content.split('\n'); + + let inUnreleased = false; + const sectionLines = new Set(); + + for (const line of lines) { + // Find unreleased header. + if (line.trim().match(/^##\s+\[Unreleased\]/u)) { + inUnreleased = true; + continue; + } + + // Stop if we hit the next version header (## [x.x.x]). + if (inUnreleased && line.trim().match(/^##\s+\[/u)) { + break; + } + + // If inside the unreleased header, add lines to the set. + if (inUnreleased) { + sectionLines.add(line.trim()); + } + } + + return sectionLines; +} + +/** + * Get the lines that were added in the PR content compared to the base content. + * + * @param {string} oldContent - The base changelog content. + * @param {string} newContent - The PR changelog content. + * @returns {string[]} The added lines as an array of strings. + */ +function getAddedLines(oldContent, newContent) { + const oldLines = new Set(oldContent.split('\n').map((line) => line.trim())); + const newLines = newContent.split('\n').map((line) => line.trim()); + + return newLines.filter( + (line) => + line.length > 0 && + !oldLines.has(line) && + !line.startsWith('#') && + !line.startsWith('['), + ); +} + +const mergedUnreleased = getUnreleasedSection(mergedContent); +const addedLines = getAddedLines(baseContent, prContent); + +const missingLines = []; +for (const line of addedLines) { + if (!mergedUnreleased.has(line)) { + missingLines.push(line); + } +} + +if (missingLines.length > 0) { + console.error( + `The following lines added in the PR are missing from the "Unreleased" section after merge:\n\n- ${missingLines.join('\n- ')}\n\nPlease update your pull request and ensure that new changelog entries remain in the "Unreleased" section.`, + ); + + process.exitCode = 1; +} diff --git a/.github/workflows/lint-build-test.yml b/.github/workflows/lint-build-test.yml index 70ac9fe5cb7..e7e83888aef 100644 --- a/.github/workflows/lint-build-test.yml +++ b/.github/workflows/lint-build-test.yml @@ -70,6 +70,21 @@ jobs: exit 1 fi + validate-changelog-diffs: + name: Validate changelog diffs + if: github.event_name == 'pull_request' || github.event_name == 'merge_group' + runs-on: ubuntu-latest + needs: prepare + steps: + - name: Checkout repository + uses: actions/checkout@v6 + - name: Validate changelog diffs + uses: ./.github/actions/check-merge-queue-changelogs + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + base-ref: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} + head-ref: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} + build: name: Build runs-on: ubuntu-latest From 959c82895689206459e8a0b1779177b3af727b2f Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:00:38 +0100 Subject: [PATCH 02/10] Fix getting PR number for pull_request trigger --- .../actions/check-merge-queue-changelogs/action.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index 4bd2a027dcc..b4405e404d2 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -17,9 +17,8 @@ runs: using: composite steps: - name: Checkout repository - uses: MetaMask/action-checkout-and-setup@v2 + uses: actions/checkout@v6 with: - is-high-risk-environment: false fetch-depth: 0 - name: Get pull request number @@ -27,10 +26,17 @@ runs: uses: actions/github-script@v8 env: HEAD_REF: ${{ inputs.head-ref }} + EVENT_NAME: ${{ github.event_name }} with: github-token: ${{ inputs.github-token }} script: | - const { HEAD_REF } = process.env; + const { EVENT_NAME, HEAD_REF } = process.env; + + if (EVENT_NAME === 'pull_request') { + const prNumber = github.context.payload.pull_request.number; + return core.setOutput('pr-number', prNumber); + } + const match = HEAD_REF.match(/\/pr-([0-9]+)-/u); if (!match) { return core.setFailed(`Could not extract pull request number from head ref: "${HEAD_REF}".`); From 1bcd40cec78b40c13bc76a50d066c50cc117352d Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:03:13 +0100 Subject: [PATCH 03/10] Fix logic --- .github/actions/check-merge-queue-changelogs/action.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index b4405e404d2..fe2984b872c 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -26,14 +26,13 @@ runs: uses: actions/github-script@v8 env: HEAD_REF: ${{ inputs.head-ref }} - EVENT_NAME: ${{ github.event_name }} with: github-token: ${{ inputs.github-token }} script: | - const { EVENT_NAME, HEAD_REF } = process.env; + const { HEAD_REF } = process.env; - if (EVENT_NAME === 'pull_request') { - const prNumber = github.context.payload.pull_request.number; + if (github.event_name === 'pull_request') { + const prNumber = github.event.pull_request.number; return core.setOutput('pr-number', prNumber); } From 057789c3973905783a6682c23ae12d0bb8e4df9f Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:08:03 +0100 Subject: [PATCH 04/10] Fix logic again --- .github/actions/check-merge-queue-changelogs/action.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index fe2984b872c..fa4cac00c5b 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -26,12 +26,13 @@ runs: uses: actions/github-script@v8 env: HEAD_REF: ${{ inputs.head-ref }} + EVENT_NAME: ${{ github.event_name }} with: github-token: ${{ inputs.github-token }} script: | - const { HEAD_REF } = process.env; + const { EVENT_NAME, HEAD_REF } = process.env; - if (github.event_name === 'pull_request') { + if (EVENT_NAME === 'pull_request') { const prNumber = github.event.pull_request.number; return core.setOutput('pr-number', prNumber); } From 245dcb3ac3ea0ce356a19323c8730c98799408bc Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:11:23 +0100 Subject: [PATCH 05/10] Use `context` instead of `github` --- .github/actions/check-merge-queue-changelogs/action.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index fa4cac00c5b..6cc26dc70fc 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -26,14 +26,13 @@ runs: uses: actions/github-script@v8 env: HEAD_REF: ${{ inputs.head-ref }} - EVENT_NAME: ${{ github.event_name }} with: github-token: ${{ inputs.github-token }} script: | const { EVENT_NAME, HEAD_REF } = process.env; - if (EVENT_NAME === 'pull_request') { - const prNumber = github.event.pull_request.number; + if (context.eventName === 'pull_request') { + const prNumber = context.payload.pull_request.number; return core.setOutput('pr-number', prNumber); } From e98e8b0ea118e1dc4ab82e4253800339f51174d3 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:14:44 +0100 Subject: [PATCH 06/10] Add missing `GH_TOKEN` --- .github/actions/check-merge-queue-changelogs/action.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index 6cc26dc70fc..101519128cf 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -50,6 +50,7 @@ runs: env: REPOSITORY: ${{ github.repository }} PR_NUMBER: ${{ steps.pr-number.outputs.pr-number }} + GH_TOKEN: ${{ inputs.github-token }} run: | BRANCH=$(gh api "/repos/${REPOSITORY}/pulls/${PR_NUMBER} --jq=.head.ref") echo "pr-branch=$BRANCH" >> "$GITHUB_OUTPUT" From cb7cb98d68e5a8f9dc6fbadc3d2f75dd3aa50c60 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 14:21:44 +0100 Subject: [PATCH 07/10] Fix command --- .github/actions/check-merge-queue-changelogs/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index 101519128cf..f158cfda3f1 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -67,7 +67,7 @@ runs: run: | set -euo pipefail - UPDATED_CHANGELOGS=$(git diff origin/"$BASE_REF"...origin/"$PR_BRANCH" --name-only | grep -E 'CHANGELOG\.md$' || true) + UPDATED_CHANGELOGS=$(git diff --name-only origin/"$BASE_REF"...origin/"$PR_BRANCH" | grep -E 'CHANGELOG\.md$' || true) if [ -n "$UPDATED_CHANGELOGS" ]; then for FILE in $UPDATED_CHANGELOGS; do git show origin/"$BASE_REF":"$FILE" > /tmp/base-changelog.md From f20516b267809367b31c7a581590133ba6e3e249 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 17 Dec 2025 18:56:36 +0100 Subject: [PATCH 08/10] Clean up logic and fix issues --- .../check-merge-queue-changelogs/action.yml | 33 +++++++++++-------- .../check-changelog-diff.cjs | 2 +- .github/workflows/lint-build-test.yml | 4 --- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index f158cfda3f1..f32c7628b52 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -3,15 +3,10 @@ description: Check if the changelog was incorrectly merged in a merge queue pull request. inputs: - head-ref: - description: The head ref of the pull request. - required: true - base-ref: - description: The base ref to compare against. - required: true github-token: description: The GitHub token to use for authentication. - required: true + required: false + default: ${{ github.token }} runs: using: composite @@ -25,7 +20,7 @@ runs: id: pr-number uses: actions/github-script@v8 env: - HEAD_REF: ${{ inputs.head-ref }} + HEAD_REF: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} with: github-token: ${{ inputs.github-token }} script: | @@ -52,25 +47,37 @@ runs: PR_NUMBER: ${{ steps.pr-number.outputs.pr-number }} GH_TOKEN: ${{ inputs.github-token }} run: | - BRANCH=$(gh api "/repos/${REPOSITORY}/pulls/${PR_NUMBER} --jq=.head.ref") + BRANCH=$(gh api "/repos/${REPOSITORY}/pulls/${PR_NUMBER}" --jq=.head.ref) echo "pr-branch=$BRANCH" >> "$GITHUB_OUTPUT" - name: Check changelog changes id: changelog-check shell: bash env: - REF: ${{ inputs.ref }} - BASE_REF: ${{ inputs.base-ref }} + HEAD_REF: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} + BASE_REF: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} PR_BRANCH: ${{ steps.pr-branch.outputs.pr-branch }} REPOSITORY: ${{ github.repository }} ACTION_PATH: ${{ github.action_path }} run: | set -euo pipefail - UPDATED_CHANGELOGS=$(git diff --name-only origin/"$BASE_REF"...origin/"$PR_BRANCH" | grep -E 'CHANGELOG\.md$' || true) + # Strip invalid prefix from `BASE_REF` + # It comes prefixed with `refs/heads/`, but the branch is not checked out in this context + # We need to express it as a remote branch + PREFIXED_REF_REGEX='refs/heads/(.+)' + if [[ "$BASE_REF" =~ $PREFIXED_REF_REGEX ]]; then + BASE_REF="${BASH_REMATCH[1]}" + fi + + TARGET_REF=$(git merge-base "origin/$BASE_REF" "origin/$PR_BRANCH") + git fetch origin "$TARGET_REF" + + UPDATED_CHANGELOGS=$(git diff --name-only "$TARGET_REF" "origin/$PR_BRANCH" | grep -E 'CHANGELOG\.md$' || true) if [ -n "$UPDATED_CHANGELOGS" ]; then for FILE in $UPDATED_CHANGELOGS; do - git show origin/"$BASE_REF":"$FILE" > /tmp/base-changelog.md + echo "Checking changelog file: $FILE" + git show "$TARGET_REF":"$FILE" > /tmp/base-changelog.md git show origin/"$PR_BRANCH":"$FILE" > /tmp/pr-changelog.md node "${ACTION_PATH}/check-changelog-diff.cjs" \ diff --git a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs index d220ea30390..b32d3881581 100644 --- a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs +++ b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs @@ -87,7 +87,7 @@ for (const line of addedLines) { if (missingLines.length > 0) { console.error( - `The following lines added in the PR are missing from the "Unreleased" section after merge:\n\n- ${missingLines.join('\n- ')}\n\nPlease update your pull request and ensure that new changelog entries remain in the "Unreleased" section.`, + `The following lines added in the PR are missing from the "Unreleased" section after merge:\n\n ${missingLines.join('\n ')}\n\nPlease update your pull request and ensure that new changelog entries remain in the "Unreleased" section.`, ); process.exitCode = 1; diff --git a/.github/workflows/lint-build-test.yml b/.github/workflows/lint-build-test.yml index e7e83888aef..770799adbca 100644 --- a/.github/workflows/lint-build-test.yml +++ b/.github/workflows/lint-build-test.yml @@ -80,10 +80,6 @@ jobs: uses: actions/checkout@v6 - name: Validate changelog diffs uses: ./.github/actions/check-merge-queue-changelogs - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - base-ref: ${{ github.event.pull_request.base.ref || github.event.merge_group.base_ref }} - head-ref: ${{ github.event.pull_request.head.ref || github.event.merge_group.head_ref }} build: name: Build From 1bcbfc95165108e57adba11b38f99e48d96cc8f8 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 18 Dec 2025 10:47:42 +0100 Subject: [PATCH 09/10] Only check unreleased section for main and PR changelog --- .../check-merge-queue-changelogs/check-changelog-diff.cjs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs index b32d3881581..a81998026c0 100644 --- a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs +++ b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs @@ -76,7 +76,10 @@ function getAddedLines(oldContent, newContent) { } const mergedUnreleased = getUnreleasedSection(mergedContent); -const addedLines = getAddedLines(baseContent, prContent); +const addedLines = getAddedLines( + getUnreleasedSection(baseContent), + getUnreleasedSection(prContent), +); const missingLines = []; for (const line of addedLines) { From 04224caf2cec224f710e34dbbcd642e2abbb888a Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Thu, 18 Dec 2025 10:59:14 +0100 Subject: [PATCH 10/10] Check if file exists on target ref and fix diff algorithm --- .../check-merge-queue-changelogs/action.yml | 10 +++++++ .../check-changelog-diff.cjs | 28 ++++++++++++------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/.github/actions/check-merge-queue-changelogs/action.yml b/.github/actions/check-merge-queue-changelogs/action.yml index f32c7628b52..8d9be178285 100644 --- a/.github/actions/check-merge-queue-changelogs/action.yml +++ b/.github/actions/check-merge-queue-changelogs/action.yml @@ -76,6 +76,16 @@ runs: UPDATED_CHANGELOGS=$(git diff --name-only "$TARGET_REF" "origin/$PR_BRANCH" | grep -E 'CHANGELOG\.md$' || true) if [ -n "$UPDATED_CHANGELOGS" ]; then for FILE in $UPDATED_CHANGELOGS; do + if [ ! -f "$FILE" ]; then + echo "Changelog file \"$FILE\" was deleted in this PR. Skipping." + continue + fi + + if ! git cat-file -e "$TARGET_REF":"$FILE" 2>/dev/null; then + echo "Changelog file \"$FILE\" is new in this PR. Skipping." + continue + fi + echo "Checking changelog file: $FILE" git show "$TARGET_REF":"$FILE" > /tmp/base-changelog.md git show origin/"$PR_BRANCH":"$FILE" > /tmp/pr-changelog.md diff --git a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs index a81998026c0..857ec8a7510 100644 --- a/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs +++ b/.github/actions/check-merge-queue-changelogs/check-changelog-diff.cjs @@ -13,9 +13,20 @@ if (process.argv.length < 5) { } /* eslint-disable n/no-sync */ -const baseContent = fs.readFileSync(process.argv[2], 'utf8'); -const prContent = fs.readFileSync(process.argv[3], 'utf8'); -const mergedContent = fs.readFileSync(process.argv[4], 'utf8'); +// The type of these is inferred as `Buffer` when using "utf-8" directly instead +// of an options object. Even though it's a plain JavaScript file, it's nice to +// keep the types correct. +const baseContent = fs.readFileSync(process.argv[2], { + encoding: 'utf-8', +}); + +const prContent = fs.readFileSync(process.argv[3], { + encoding: 'utf-8', +}); + +const mergedContent = fs.readFileSync(process.argv[4], { + encoding: 'utf-8', +}); /* eslint-enable n/no-sync */ /** @@ -58,15 +69,12 @@ function getUnreleasedSection(content) { /** * Get the lines that were added in the PR content compared to the base content. * - * @param {string} oldContent - The base changelog content. - * @param {string} newContent - The PR changelog content. + * @param {Set} oldLines - The base changelog content. + * @param {Set} newLines - The PR changelog content. * @returns {string[]} The added lines as an array of strings. */ -function getAddedLines(oldContent, newContent) { - const oldLines = new Set(oldContent.split('\n').map((line) => line.trim())); - const newLines = newContent.split('\n').map((line) => line.trim()); - - return newLines.filter( +function getAddedLines(oldLines, newLines) { + return Array.from(newLines).filter( (line) => line.length > 0 && !oldLines.has(line) &&