Skip to content
This repository has been archived by the owner on Sep 20, 2024. It is now read-only.

Commit

Permalink
Fix: Empty PR Body Error (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
therynamo authored Oct 15, 2019
1 parent f8ec1bc commit 496ffd3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/facades/ReleaseCommunicationFacade.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,17 @@ class ReleaseCommunication {
const pullRequests = await Promise.all(uniquePRNumbers.map(async prNum => getPullRequestHandler(this.owner, this.repo, prNum)));

const pullRequestMessages = Promise.all(pullRequests.map(async (pr) => {
const stripIgnoreTickets = pr.body.replace(STRIP_IGNORE_TICKETS, '');
// Initialize body in case the PR description is empty.
const body = pr.body || '';

const stripIgnoreTickets = body.replace(STRIP_IGNORE_TICKETS, '');
const noCommentBody = stripIgnoreTickets.replace(PR_TEMPLATE_COMMENT_REGEX, '');

const ticketGroups = await ticketFinder(noCommentBody);

return {
number: pr.number,
message: pr.body,
message: body,
...ticketGroups,
title: pr.title,
};
Expand Down
17 changes: 17 additions & 0 deletions src/facades/__tests__/ReleaseCommunicationFacade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ describe('ReleaseCommunicationFacade', () => {
expect(diff).toEqual(expectedDiff);
});

it('should parse a diff response when a pull request has no body', async () => {
expect.assertions(1);
handlers.getPullRequestHandler.mockResolvedValueOnce({ ...pullRequestResponse, body: null });
const diff = await RC.parseDiff(squashDiffResponse);
const expectedDiff = [
{
github: { name: 'github', tickets: [] },
jira: { name: 'jira', tickets: [] },
message: '',
number: 1,
title: 'bla',
},
];

expect(diff).toEqual(expectedDiff);
});

it('should handle the retrieval and parse of non-squashed commits', async () => {
expect.assertions(2);
handlers.getTagsHandler.mockResolvedValue(tagResponse);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ module.exports = async function App(config) {

populateMessages(defaultTeam)(teamList, sortedMessages);

const { message, attachments, subChannelAttachments } = createAttachment(messages.length, { owner, repo });
const { message, attachments, subChannelAttachments = [] } = createAttachment(messages.length, { owner, repo });

logger.info(`\n Slack Formatter Url. CMD+Click to open in your default browser \n \n ${generateSlackFormatterUrl(attachments)}`);

Expand Down

0 comments on commit 496ffd3

Please sign in to comment.