Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trim comment, review, etc. bodies at the first <hr>. #637

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/messages/abstract-issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class AbstractIssue extends Message {
};
if (this.major) {
if (this.abstractIssue.body_html) {
const { text, image } = mrkdwn(this.abstractIssue.body_html);
const { text, image } = mrkdwn(this.abstractIssue.body_html, { trimAt: 'hr' });
core.text = text;
core.image_url = image;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/messages/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Comment extends Message {
};

if (this.comment.body_html) {
const { text, image } = mrkdwn(this.comment.body_html);
const { text, image } = mrkdwn(this.comment.body_html, { trimAt: 'hr' });
baseMessage.text = text;
baseMessage.image_url = image;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/messages/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Release extends Message {
};

if (release.body_html) {
const { text, image } = mrkdwn(release.body_html);
const { text, image } = mrkdwn(release.body_html, { trimAt: 'hr' });
message.text = text;
message.image_url = image;
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/messages/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Review extends Message {
};

if (this.review.body_html) {
const { text, image } = mrkdwn(this.review.body_html);
const { text, image } = mrkdwn(this.review.body_html, { trimAt: 'hr' });
baseMessage.text = text;
baseMessage.image_url = image;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"express-async-errors": "^2.1.1",
"express-sslify": "^1.2.0",
"helmet": "^3.11.0",
"html-to-mrkdwn": "^3.0.0",
"html-to-mrkdwn": "^3.1.0",
"isbinaryfile": "^3.0.3",
"jsonwebtoken": "^8.1.0",
"keyv": "^3.0.0",
Expand Down
13 changes: 13 additions & 0 deletions test/messages/Comment.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ describe('Comment rendering', () => {
expect(message.getRenderedMessage().text).toEqual('*Hello* _cruel_ <http://example.com|world>');
});

test('trims HTML body after hr', () => {
const message = new Comment({
comment: Object.assign({
body_html: '<strong>Hello</strong> <hr> <em>cruel</em> <a href="http://example.com">world</a>',
}, comment),
repository,
issue,
unfurlType: 'full',
});

expect(message.getRenderedMessage().text).toEqual('*Hello* ');
});

test('extracts image from body_html', () => {
const message = new Comment({
comment: Object.assign({
Expand Down
8 changes: 8 additions & 0 deletions test/messages/Review.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ describe('Review rendering', () => {
});
expect(reviewMessage.toJSON()).toMatchSnapshot();
});

test('trims html after hr', async () => {
const reviewMessage = new Review({
...reviewApproved,
review: { ...reviewApproved.review, body_html: '<b>rendered</b> <hr> <code>html</code>' },
});
expect(reviewMessage.toJSON()).toMatchSnapshot();
});
});
21 changes: 21 additions & 0 deletions test/messages/__snapshots__/Review.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Review rendering trims html after hr 1`] = `
Object {
"author_icon": "https://avatars1.githubusercontent.com/u/10660468?v=4",
"author_link": "https://github.com/JasonEtco",
"author_name": "JasonEtco",
"color": "#36a64f",
"fallback": "[github-slack/public-test] JasonEtco approved wilhelmklopp's pull request",
"footer": "<https://github.com/github-slack/public-test|github-slack/public-test>",
"footer_icon": "https://assets-cdn.github.com/favicon.ico",
"image_url": undefined,
"mrkdwn_in": Array [
"text",
],
"pretext": "JasonEtco approved wilhelmklopp's pull request",
"text": "*rendered* ",
"title": "Review on #19 removing more words",
"title_link": "https://github.com/github-slack/public-test/pull/19#pullrequestreview-97014958",
"ts": 1518730621,
}
`;

exports[`Review rendering renders html to mrkdwn 1`] = `
Object {
"author_icon": "https://avatars1.githubusercontent.com/u/10660468?v=4",
Expand Down
12 changes: 12 additions & 0 deletions test/messages/abstract-issue.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@ describe('AbstractIssue rendering', () => {

expect(message.getCore().text).toEqual('*Hello* _cruel_ <http://example.com|world>');
});

test('trims HTML body after hr', () => {
const message = new AbstractIssue({
abstractIssue: Object.assign({
body_html: '<strong>Hello</strong> <hr> <em>cruel</em> <a href="http://example.com">world</a>',
}, fixtures.issue),
repository: fixtures.repo,
unfurlType: 'full',
});

expect(message.getCore().text).toEqual('*Hello* ');
});
});