Skip to content

Commit

Permalink
Merge pull request #54 from millerick/mmillerick/replace-in-place
Browse files Browse the repository at this point in the history
Replace Jira information in the location it originally appeared in the pull request description
  • Loading branch information
cakeinpanic authored Jun 21, 2024
2 parents eba1385 + ba599fe commit ce79342
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ jobs:
```
`
## Features
When a PR passes the above check, `jira-description-action` will also add the issue details to the top of the PR description.
When a PR passes the above check, `jira-description-action` will also add the issue details to the top of the PR description. The issue details can be placed in a specific section of the PR description by including the following markers in the [pull request template](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/creating-a-pull-request-template-for-your-repository#adding-a-pull-request-template) for the repository.
```
<!--jira-description-action-hidden-marker-start-->

<!--jira-description-action-hidden-marker-end-->
```
### Options
Expand Down
14 changes: 13 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,17 @@ ${HIDDEN_MARKER_START}
${issueInfo}
${HIDDEN_MARKER_END}
${oldPRBodyInformation}`);
})
});

it('respects the location of HIDDEN_MARKER_START and HIDDEN_MARKER_END when they already exist in the pull request body', () => {
const issueInfo = 'new info about jira task';
const oldPRDescription = `this is text above the markers
${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
${issueInfo}
${HIDDEN_MARKER_END}
this is text below the markers`;
const description = getPRDescription(oldPRDescription, issueInfo);
expect(description).toEqual(oldPRDescription);
});
});
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ export const getPRDescription = (oldBody: string, details: string): string => {

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}
const jiraDetailsMessage = `${WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS}
${HIDDEN_MARKER_START}
${details}
${HIDDEN_MARKER_END}
${bodyWithoutJiraDetails}`;
`;
if (replaceDetailsRg.test(oldBody)) {
return (oldBody ?? '').replace(replaceWarningMessageRg, '').replace(replaceDetailsRg, jiraDetailsMessage);
}
return jiraDetailsMessage + oldBody;
};

export const buildPRDescription = (details: JIRADetails) => {
Expand Down

0 comments on commit ce79342

Please sign in to comment.