Skip to content

Commit

Permalink
feat(discord: commands): if issue description contains image, add and…
Browse files Browse the repository at this point in the history
… send with embed
  • Loading branch information
dsevillamartin committed May 8, 2017
1 parent 229a29b commit 17ca650
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Discord/Commands/GitlabIssue.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class GitlabIssue extends Command {
run(msg, args) {
if (!args[0]) return this.errorUsage(msg);

if (args[0] === 'search') return this._search(msg, args);
if (args[0] === 'search' && args.length > 1) return this._search(msg, args);
if (args.length === 1) return this._issue(msg, args);

return this.errorUsage(msg);
Expand All @@ -40,12 +40,14 @@ class GitlabIssue extends Command {

return Gitlab.getProjectIssue(repository, null, issueNumber)
.then(res => {
let issue = res.body;
const issue = res.body;
const description = issue.description;
const [, imageUrl] = /!\[(?:.*?)\]\((.*?)\)/.exec(description) || [];

const embed = new this.embed()
.setTitle(`Issue \`#${issue.iid}\` - ${issue.title}`)
.setURL(issue.web_url)
.setDescription(`\u200B\n${issue.description}\n\u200B`)
.setDescription(`\u200B\n${description.slice(0, 2040)}\n\u200B`)
.setColor('#84F139')
.addField('Status', issue.state === 'opened' ? 'Open' : 'Closed', true)
.addField('Labels', issue.labels.length ? issue.labels.map(e => `\`${e}\``).join(', ') : 'None', true)
Expand All @@ -54,6 +56,7 @@ class GitlabIssue extends Command {
.addField('Assignee', issue.assignee ? `[${issue.assignee.name}](${issue.assignee.web_url})` : 'None', true)
.addField('Comments', issue.user_notes_count, true)
.setFooter(repository, this.bot.user.avatarURL);
if (imageUrl) embed.setImage(imageUrl.startsWith('/') ? `https://gitlab.com/${repository}/${imageUrl}` : imageUrl);

return msg.channel.send({ embed });
}).catch(err => {
Expand Down

0 comments on commit 17ca650

Please sign in to comment.