Skip to content

Commit

Permalink
Merge pull request #51 from javierjulio/html-output-update
Browse files Browse the repository at this point in the history
Use valid table HTML for PR description
  • Loading branch information
cakeinpanic authored Jun 21, 2024
2 parents 235b829 + 14cdca3 commit a5ec29c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
27 changes: 26 additions & 1 deletion __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HIDDEN_MARKER_END, HIDDEN_MARKER_START, WARNING_MESSAGE_ABOUT_HIDDEN_MARKERS } from '../src/constants';
import { getJIRAIssueKeyByDefaultRegexp, getJIRAIssueKeysByCustomRegexp, getPRDescription, shouldSkipBranch } from '../src/utils';
import { JIRADetails } from '../src/types';
import { getJIRAIssueKeyByDefaultRegexp, getJIRAIssueKeysByCustomRegexp, getPRDescription, shouldSkipBranch, buildPRDescription } from '../src/utils';

jest.spyOn(console, 'log').mockImplementation(); // avoid actual console.log in test output

Expand Down Expand Up @@ -112,3 +113,27 @@ this is text below the markers`;
expect(description).toEqual(oldPRDescription);
});
});

describe('buildPRDescription()', () => {
it('should return description HTML from the JIRA details', () => {
const details: JIRADetails = {
key: 'ABC-123',
summary: 'Sample summary',
url: 'example.com/ABC-123',
type: {
name: 'story',
icon: 'icon.png',
},
project: {
name: 'name',
url: 'url',
key: 'key',
},
};

expect(buildPRDescription(details)).toEqual(`<table><tbody><tr><td>
<a href="example.com/ABC-123" title="ABC-123" target="_blank"><img alt="story" src="icon.png" /> ABC-123</a>
Sample summary
</td></tr></tbody></table><br />`);
});
});
12 changes: 4 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,8 @@ ${HIDDEN_MARKER_END}

export const buildPRDescription = (details: JIRADetails) => {
const displayKey = details.key.toUpperCase();
return `
<table>
<td>
<a href="${details.url}" title="${displayKey}" target="_blank"><img alt="${details.type.name}" src="${details.type.icon}" />${displayKey}</a> ${details.summary}
</td></table>
<br />
`;
return `<table><tbody><tr><td>
<a href="${details.url}" title="${displayKey}" target="_blank"><img alt="${details.type.name}" src="${details.type.icon}" /> ${displayKey}</a>
${details.summary}
</td></tr></tbody></table><br />`;
};

0 comments on commit a5ec29c

Please sign in to comment.