Skip to content

Commit

Permalink
fix: don't trim null notes (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Aug 31, 2020
1 parent 51c1a9b commit 04fc9c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/__tests__/note.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ describe('comment generation', () => {
expect(noteUtils.createPRCommentFromNotes('no-notes')).toEqual(constants.NO_NOTES_BODY);
});

it('can handle missing notes', () => {
const note = noteUtils.findNoteInPRBody('oh no');
expect(noteUtils.createPRCommentFromNotes(note)).toEqual(constants.NO_NOTES_BODY);

expect(noteUtils.createPRCommentFromNotes('no-notes')).toEqual(constants.NO_NOTES_BODY);
});

it('does not false positively match no-notes', () => {
const surpriseNote = noteUtils.findNoteInPRBody(prBodyWithSurpriseNote);
const comment = noteUtils.createPRCommentFromNotes(surpriseNote);
Expand Down
8 changes: 4 additions & 4 deletions src/note-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ export const findNoteInPRBody = (body: string): string | null => {
notes = multilineMatch[1];
}

// remove the default PR template
if (notes) {
debug(`Found Notes: ${JSON.stringify(notes.trim())}`);

// Remove the default PR template.
notes = notes.replace(/<!--.*?-->/g, '');
}

debug(`Found Notes: ${JSON.stringify(notes.trim())}`);

return notes.trim();
return notes ? notes.trim() : notes;
};

const OMIT_FROM_RELEASE_NOTES_KEYS = [
Expand Down

0 comments on commit 04fc9c3

Please sign in to comment.