diff --git a/lib/bot.js b/lib/bot.js index e57747a..1962253 100644 --- a/lib/bot.js +++ b/lib/bot.js @@ -3,6 +3,7 @@ const JiraApi = require('jira-client'); const Botkit = require('botkit'); const moment = require('moment'); +const J2S = require('jira2slack'); const logger = require('./logger')(); const RESPONSE_FULL = 'full'; @@ -149,90 +150,7 @@ class Bot { */ formatIssueDescription (description) { const desc = description || 'Ticket does not contain a description'; - let depths = []; - let lastDepth = 0; - return desc - // Quotes - .replace(/\{(quote)\}/g, '```') - - // Stolen from: https://github.com/kylefarris/J2M - // Un-ordered Lists - .replace(/^[ \t]*(\*+)\s+/gm, (match, stars) => `${Array(stars.length).join(' ')}• `) - .replace(/^\-\s+/gm, () => '• ') - - // Ordered lists - .replace(/^[ \t]*(#+)\s+/gm, (match, nums) => { - const curDepth = nums.length - 1; - if (curDepth === lastDepth) { - depths[curDepth] = depths[curDepth] !== undefined ? depths[curDepth] + 1 : 1; - } else if (curDepth > lastDepth) { - depths[curDepth] = 1; - } else if (curDepth < lastDepth) { - depths = depths.slice(0, curDepth + 1); - depths[curDepth]++; - } - - lastDepth = curDepth; - return `${Array(curDepth + 1).join(' ')}${depths[curDepth]}. `; - }) - - // Headers 1-6 - .replace(/^h([0-6])\.(\s*)(.*)$/gm, - (match, level, spacing, content) => `\n${spacing}*${content}*\n`) - - // Bold - .replace(/\*(\s*)(\S.*?\S)(\s*)\*/g, '$1*$2*$3') - - // Italic - .replace(/_(\s*)(\S.*?\S)(\s*)_/g, '$1_$2_$3') - - // Monospaced text - .replace(/\{\{([^}]+)\}\}/g, '`$1`') - - // Citations - .replace(/\?\?((?:.[^?]|[^?].)+)\?\?/g, '_-- $1_') - - // Inserts (ignored as unsupported) - // .replace(/\+([^+]*)\+/g, '$1') - - // Superscript - .replace(/\^([^^]*)\^/g, '^$1') - - // Subscript - .replace(/~([^~]*)~/g, '_$1') - - // Strikethrough - .replace(/((\W)\-|(^)\-)( *)(\S.*?\S)( *)(\-(\W)|\-($))/gm, '$2$3$4~$5~$6$8') - - // Code Block - .replace(/\{code(:([a-z]+))?\}([^]*)\{code\}/gm, '```$2$3```') - - // Pre-formatted text - .replace(/{noformat}/g, '```') - - // Un-named Links - .replace(/\[([^|]+)\]/g, '<$1>') - - // Named Links - .replace(/\[(.+?)\|(.+)\]/g, '<$2|$1>') - - // Single Paragraph Blockquote - .replace(/^bq\.\s+/gm, '> ') - - // Remove color: unsupported in md - .replace(/\{color:[^}]+\}([^]*)\{color\}/gm, '$1') - - // panel into table - .replace(/\{panel:title=([^}]*)\}\n?([^]*?)\n?\{panel\}/gm, '\n| $1 |\n| --- |\n| $2 |') - - // table header - .replace(/^[ \t]*((?:\|\|.*?)+\|\|)[ \t]*$/gm, (match, headers) => { - const singleBarred = headers.replace(/\|\|/g, '|'); - return `\n${singleBarred}\n${singleBarred.replace(/\|[^|]+/g, '| --- ')}`; - }) - - // remove leading-space of table headers and rows - .replace(/^[ \t]*\|/gm, '|'); + return J2S.toSlack(desc); } /** diff --git a/package.json b/package.json index 8b9d1fd..653dd10 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "slack-jirabot", - "version": "2.3.0", + "version": "2.3.1", "description": "Slackbot for interacting with JIRA", "main": "app.js", "private": true, @@ -24,6 +24,7 @@ "dependencies": { "botkit": "^0.1.1", "jira-client": "^3.0.2", + "jira2slack": "^0.1.0", "moment": "^2.10.3", "redact-object": "^1.0.1", "winston": "^2.1.1"