From e5e7155eb5de027b2ddd41df471ad6e36c7df3cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sevilla=20Mart=C3=ADn?= Date: Sun, 17 Jun 2018 18:47:32 -0400 Subject: [PATCH] fix(gitlab): move embed description limit into handler parser fix way too long descriptions (over 2048 chars) --- lib/Gitlab/EventHandler.js | 3 +++ lib/Gitlab/Events/issue.js | 3 ++- lib/Gitlab/Events/tag_push.js | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Gitlab/EventHandler.js b/lib/Gitlab/EventHandler.js index 6a8a6b9..c2e864d 100644 --- a/lib/Gitlab/EventHandler.js +++ b/lib/Gitlab/EventHandler.js @@ -84,6 +84,9 @@ class Events { }; embed.url = embed.url || (data.object_attributes && data.object_attributes.url) || data.project.web_url; embed.timestamp = new Date(); + + embed.description = embed.description.slice(0, 1000) + (embed.description.length > 1000 ? '...' : ''); + return embed; } } diff --git a/lib/Gitlab/Events/issue.js b/lib/Gitlab/Events/issue.js index 7a29520..4340f49 100644 --- a/lib/Gitlab/Events/issue.js +++ b/lib/Gitlab/Events/issue.js @@ -16,7 +16,8 @@ class Issue extends EventResponse { description: 'A test issue event was fired from the GitLab integrations page', fields: [{ name: 'Description', - value: `${issue.description.split('\n').slice(0, 4).join('\n').slice(0, 2000)}\n\u200B`, + value: `${issue.description.split('\n').slice(0, 4).join('\n') + .slice(0, 2000)}\n\u200B`, }, { name: 'State', value: issue.state[0].toUpperCase() + issue.state.slice(1), diff --git a/lib/Gitlab/Events/tag_push.js b/lib/Gitlab/Events/tag_push.js index 3500f46..e62f004 100644 --- a/lib/Gitlab/Events/tag_push.js +++ b/lib/Gitlab/Events/tag_push.js @@ -18,7 +18,7 @@ class TagPush extends EventResponse { color: 0xF0C330, title: `${this.isCreated(data) ? 'Created' : 'Deleted'} tag \`${tag}\` ${sha ? `from commit \`${sha}\`` : ''}${isCreated ? ` with ${commitCount} ${commitCount !== 1 ? 'commits' : 'commit'}` : ''}`, url: isCreated ? `${data.project.web_url}/tags/${tag}` : null, - description: `${message.slice(0, 2000)}${message.length > 2000 ? '...' : ''}`, + description: message, }; } @@ -32,7 +32,7 @@ class TagPush extends EventResponse { return [ `⚡ **${actor}** ${isCreated ? 'created' : 'deleted'} tag \`${tag}\` ${sha ? `from commit \`${sha}\`` : ''}${isCreated ? `with ${commitCount} ${commitCount !== 1 ? 'commits' : 'commit'}` : ''}`, - ` ${message.slice(0, 200)}${message.length > 200 ? '...' : ''}`, ` `, + ` ${message.split('\n')[0]}`, ` `, `${isCreated ? `<${data.project.web_url}/tags/${tag}>` : ''}`, ].filter(e => e !== '').join('\n'); }