Skip to content

Commit

Permalink
Merge pull request #53 from millerick/mmillerick/fix-duplication-bug
Browse files Browse the repository at this point in the history
Fix warning message duplication
  • Loading branch information
cakeinpanic authored Jun 15, 2024
2 parents c414eaf + db0cc16 commit 9a6111a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
15 changes: 15 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,19 @@ ${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBodyInformation}`);
});

it('does not duplicate WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS in the body when run multiple times', () => {
const oldPRBodyInformation = 'old PR description body';
const oldPRBody = `${HIDDEN_MARKER_START}Here is some old issue information${HIDDEN_MARKER_END}${oldPRBodyInformation}`;
const issueInfo = 'new info about jira task';

const firstDescription = getPRDescription(oldPRBody, issueInfo);
const secondDescription = getPRDescription(firstDescription, issueInfo);

expect(secondDescription).toEqual(`${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBodyInformation}`);
})
});
8 changes: 7 additions & 1 deletion lib/index.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ const escapeRegexp = (str: string): string => {
export const getPRDescription = (oldBody: string, details: string): string => {
const hiddenMarkerStartRg = escapeRegexp(HIDDEN_MARKER_START);
const hiddenMarkerEndRg = escapeRegexp(HIDDEN_MARKER_END);
const warningMsgRg = escapeRegexp(WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS);

const rg = new RegExp(`${hiddenMarkerStartRg}([\\s\\S]+)${hiddenMarkerEndRg}`, 'igm');
const bodyWithoutJiraDetails = (oldBody ?? '').replace(rg, '');
const replaceDetailsRg = new RegExp(`${hiddenMarkerStartRg}([\\s\\S]+)${hiddenMarkerEndRg}[\\s]?`, 'igm');
const replaceWarningMessageRg = new RegExp(`${warningMsgRg}[\\s]?`, 'igm');
const bodyWithoutJiraDetails = (oldBody ?? '').replace(replaceDetailsRg, '').replace(replaceWarningMessageRg, '');

return `${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
Expand Down

0 comments on commit 9a6111a

Please sign in to comment.