Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regex for multiline notes #127

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
`;