Skip to content

Commit

Permalink
fix: regex for multiline notes
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Oct 22, 2024
1 parent b1b021a commit 144725a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/note-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const debug = d('note-utils');

export const findNoteInPRBody = (body: string): string | null => {
const onelineMatch = /(?:(?:\r?\n)|^)notes: (.+?)(?:(?:\r?\n)|$)/gi.exec(body);
const multilineMatch = /(?:(?:\r?\n)Notes:(?:\r?\n+)((?:\*.+(?:(?:\r?\n)|$))+))/gi.exec(body);
const multilineMatch = /(?:(?:\r?\n?)Notes:(?:\r?\n+)((?:\*.+(?:(?:\r?\n)|$))+))/gi.exec(body);

let notes: string | null = null;
if (onelineMatch && onelineMatch[1]) {
Expand Down
24 changes: 24 additions & 0 deletions test/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,21 @@ describe('comment generation', () => {

expect(comment).toEqual(expect.stringContaining(expected));
});

it('can handle a PR body only containing a note', () => {
const note = noteUtils.findNoteInPRBody(prBodyWithOnlyNotes);
const comment = noteUtils.createPRCommentFromNotes(note);
expect(comment).toEqual(expect.stringContaining(constants.NOTES_LEAD));

const expected = `
> * Security: backported fix for CVE-2024-7965.
> * Security: backported fix for CVE-2024-7966.
> * Security: backported fix for CVE-2024-7967.
> * Security: backported fix for CVE-2024-8198.
> * Security: backported fix for CVE-2024-8193.`;

expect(comment).toEqual(expect.stringContaining(expected));
});
});

/* Test PR Bodies */
Expand Down Expand Up @@ -199,3 +214,12 @@ See that PR for details.
Notes: Fixed an issue where packages could not be selected with <input file="type"> on macOS.
`;
/* tslint:enable */

const prBodyWithOnlyNotes = `
Notes:
* Security: backported fix for CVE-2024-7965.
* Security: backported fix for CVE-2024-7966.
* Security: backported fix for CVE-2024-7967.
* Security: backported fix for CVE-2024-8198.
* Security: backported fix for CVE-2024-8193.
`;

0 comments on commit 144725a

Please sign in to comment.