Skip to content

Commit

Permalink
feat(discord: commands): if merge request description contains image,…
Browse files Browse the repository at this point in the history
… add and send with embed

also fixed so it replaces '!' and not '#' (merge requests start with !)
  • Loading branch information
dsevillamartin committed May 8, 2017
1 parent 17ca650 commit edc437e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/Discord/Commands/GitlabMergeRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ class GitlabIssue extends Command {
}

_mr(msg, args) {
const mrNumber = parseInt(args[0].replace(/#/g, ''));
const mrNumber = parseInt(args[0].replace(/!/g, ''));
let repository = ChannelConfig.FindByChannel(msg.channel.id).repo;
if (!repository) return this.commandError(msg, Gitlab.Constants.Errors.NO_REPO_CONFIGURED(this));
if (!mrNumber) return this.errorUsage(msg);

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

const embed = new this.embed()
.setTitle(`Merge Request \`#${mr.iid}\` - ${mr.title}`)
.setURL(mr.web_url)
.setDescription(mr.description.length ? `\u200B\n${mr.description}\n\u200B` : '\u200B')
.setDescription(`\u200B\n${description.slice(0, 2040)}\n\u200B`)
.setColor('#84F139')
.addField('Source', `${mr.author.username}:${mr.source_branch}`, true)
.addField('Target', `${repository.split('/')[0]}:${mr.target_branch}`, true)
Expand All @@ -58,6 +60,7 @@ class GitlabIssue extends Command {
.addField('Milestone', mr.milestone ? `${mr.milestone.title}` : 'None', true)
.addField('Comments', mr.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 edc437e

Please sign in to comment.