From f45dff6df29c2657b83d4b34d2cfe6fd72afe510 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Fri, 20 Nov 2026 07:49:28 -0800 Subject: [PATCH] fix: match green-button (#N) only on the summary line A body line ending in "(#N)", such as "see also (#12)" or a squash-merge entry "* fix: foo (#7)", overwrote prUrl/ghIssue and was dropped from description. --- commit-stream.js | 2 +- test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/commit-stream.js b/commit-stream.js index 6c36492..a2aea53 100644 --- a/commit-stream.js +++ b/commit-stream.js @@ -99,7 +99,7 @@ export default function commitStream (ghUser, ghProject) { (commit.reviewers ??= []).push({ name: m[1], email: m[2] }) } else if ((m = line.match(/^\s*CVE-ID:\s+(CVE-\d{4}-\d{4,})\b/)) !== null) { commit.cveId = m[1] - } else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) !== null) { + } else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:\s*(.+)\s*$/) || (commit.summary === undefined ? line.match(/^ {4}.*\(#(\d+)\)$/) : null)) !== null) { commit.prUrl = m[1] if (ghUser && ghProject && (m = commit.prUrl.match(/^\s*#?(\d+)\s*$/)) !== null) { commit.prUrl = `https://github.com/${ghUser}/${ghProject}/pull/${m[1]}` diff --git a/test.js b/test.js index c1abca9..0ba7b78 100644 --- a/test.js +++ b/test.js @@ -295,6 +295,24 @@ for (const line of ['PR-URL: #12', 'PR URL: #12', 'PRURL: #12', 'PR: #12']) { }) } +for (const line of ['see also (#12)', '* fix: squashed (#7)']) { + test(`body line "${line}" is kept in description`, async () => { + const commits = await toCommits([ + 'commit 0000000000000000000000000000000000000000', + 'Author: Rod Vagg ', + 'Date: Fri Apr 17 10:52:16 2015 +1000', + '', + ' doc: tidy up (#41)', + '', + ` ${line}` + ], 'rvagg', 'commit-stream') + assert.strictEqual(commits[0].prUrl, 'https://github.com/rvagg/commit-stream/pull/41') + assert.strictEqual(commits[0].ghIssue, 41) + assert.strictEqual(commits[0].summary, 'doc: tidy up') + assert.deepStrictEqual(commits[0].description, [line]) + }) +} + test('line before first commit header rejects pipeline', async () => { await assert.rejects(toCommits(['garbage']), { message: 'Unexpected line before first "commit" header: garbage'