diff --git a/commit-stream.js b/commit-stream.js index 1e04bb4..6c36492 100644 --- a/commit-stream.js +++ b/commit-stream.js @@ -97,7 +97,7 @@ export default function commitStream (ghUser, ghProject) { null ) { (commit.reviewers ??= []).push({ name: m[1], email: m[2] }) - } else if ((m = line.match(/\bCVE-ID:\s+(CVE-\d{4}-\d{4,})\b/)) !== null) { + } 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) { commit.prUrl = m[1] diff --git a/test.js b/test.js index e071717..c1abca9 100644 --- a/test.js +++ b/test.js @@ -234,6 +234,36 @@ test('cve id with 4 or more sequence digits', async () => { assert.deepStrictEqual(commits.map((c) => c.cveId), ids) }) +test('CVE-ID on the summary line is kept as the summary', async () => { + const commits = await toCommits([ + 'commit 0000000000000000000000000000000000000000', + 'Author: RafaelGSS ', + 'Date: Fri Nov 22 00:19:29 2024 -0300', + '', + ' deps: CVE-ID: CVE-2024-1234 fix', + '', + ' body line one' + ]) + assert.strictEqual(commits.length, 1) + assert.strictEqual(commits[0].summary, 'deps: CVE-ID: CVE-2024-1234 fix') + assert.deepStrictEqual(commits[0].description, ['body line one']) + assert.strictEqual(commits[0].cveId, undefined) +}) + +test('unindented CVE-ID line sets cveId', async () => { + const commits = await toCommits([ + 'commit 0000000000000000000000000000000000000000', + 'Author: RafaelGSS ', + 'Date: Fri Nov 22 00:19:29 2024 -0300', + '', + ' deps: fix vulnerability', + '', + 'CVE-ID: CVE-2024-1234' + ]) + assert.strictEqual(commits.length, 1) + assert.strictEqual(commits[0].cveId, 'CVE-2024-1234') +}) + test('body lines starting with "PR" are not PR urls', async () => { const commits = await toCommits([ 'commit 0000000000000000000000000000000000000000',