Skip to content

Commit 94719c9

Browse files
committed
fix: require colon after PR/PR-URL in body lines
1 parent 6166f5b commit 94719c9

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

‎commit-stream.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export default function commitStream (ghUser, ghProject) {
9999
(commit.reviewers ??= []).push({ name: m[1], email: m[2] })
100100
} else if ((m = line.match(/\bCVE-ID:\s+(CVE-\d{4}-\d{4,})\b/)) !== null) {
101101
commit.cveId = m[1]
102-
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:?\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) !== null) {
102+
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) !== null) {
103103
commit.prUrl = m[1]
104104
if (ghUser && ghProject && (m = commit.prUrl.match(/^\s*#?(\d+)\s*$/)) !== null) {
105105
commit.prUrl = `https://github.com/${ghUser}/${ghProject}/pull/${m[1]}`

‎test.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,37 @@ test('cve id with 4 or more sequence digits', async () => {
234234
assert.deepStrictEqual(commits.map((c) => c.cveId), ids)
235235
})
236236

237+
test('body lines starting with "PR" are not PR urls', async () => {
238+
const commits = await toCommits([
239+
'commit 0000000000000000000000000000000000000000',
240+
'Author: Rod Vagg <rod@vagg.org>',
241+
'Date: Fri Apr 17 10:52:16 2015 +1000',
242+
'',
243+
' PRs: tidy up docs',
244+
'',
245+
' PRetty much done'
246+
])
247+
assert.strictEqual(commits[0].prUrl, undefined)
248+
assert.strictEqual(commits[0].summary, 'PRs: tidy up docs')
249+
assert.deepStrictEqual(commits[0].description, ['PRetty much done'])
250+
})
251+
252+
for (const line of ['PR-URL: #12', 'PR URL: #12', 'PRURL: #12', 'PR: #12']) {
253+
test(`"${line}" is parsed as a PR url`, async () => {
254+
const commits = await toCommits([
255+
'commit 0000000000000000000000000000000000000000',
256+
'Author: Rod Vagg <rod@vagg.org>',
257+
'Date: Fri Apr 17 10:52:16 2015 +1000',
258+
'',
259+
' doc: tidy up',
260+
'',
261+
` ${line}`
262+
], 'rvagg', 'commit-stream')
263+
assert.strictEqual(commits[0].prUrl, 'https://github.com/rvagg/commit-stream/pull/12')
264+
assert.strictEqual(commits[0].summary, 'doc: tidy up')
265+
})
266+
}
267+
237268
test('line before first commit header rejects pipeline', async () => {
238269
await assert.rejects(toCommits(['garbage']), {
239270
message: 'Unexpected line before first "commit" header: garbage'

0 commit comments

Comments
 (0)