diff --git a/commit-stream.js b/commit-stream.js index 4e62fd5..1e04bb4 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(/\bCVE-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*$/) || line.match(/\(#(\d+)\)$/)) !== 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 20975cb..e071717 100644 --- a/test.js +++ b/test.js @@ -234,6 +234,37 @@ test('cve id with 4 or more sequence digits', async () => { assert.deepStrictEqual(commits.map((c) => c.cveId), ids) }) +test('body lines starting with "PR" are not PR urls', async () => { + const commits = await toCommits([ + 'commit 0000000000000000000000000000000000000000', + 'Author: Rod Vagg ', + 'Date: Fri Apr 17 10:52:16 2015 +1000', + '', + ' PRs: tidy up docs', + '', + ' PRetty much done' + ]) + assert.strictEqual(commits[0].prUrl, undefined) + assert.strictEqual(commits[0].summary, 'PRs: tidy up docs') + assert.deepStrictEqual(commits[0].description, ['PRetty much done']) +}) + +for (const line of ['PR-URL: #12', 'PR URL: #12', 'PRURL: #12', 'PR: #12']) { + test(`"${line}" is parsed as a PR url`, async () => { + const commits = await toCommits([ + 'commit 0000000000000000000000000000000000000000', + 'Author: Rod Vagg ', + 'Date: Fri Apr 17 10:52:16 2015 +1000', + '', + ' doc: tidy up', + '', + ` ${line}` + ], 'rvagg', 'commit-stream') + assert.strictEqual(commits[0].prUrl, 'https://github.com/rvagg/commit-stream/pull/12') + assert.strictEqual(commits[0].summary, 'doc: tidy up') + }) +} + test('line before first commit header rejects pipeline', async () => { await assert.rejects(toCommits(['garbage']), { message: 'Unexpected line before first "commit" header: garbage'