probot/attachments

Name: attachments

Owner: Probot

Description: A Probot extension to add message attachments to comments on GitHub

Created: 2017-10-26 04:53:27.0

Updated: 2018-04-05 00:24:56.0

Pushed: 2018-04-05 00:24:55.0

Homepage: null

Size: 14

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Probot: attachments

A Probot extension to add message attachments to comments on GitHub.

Usage
t attachments = require('probot-attachments')

le.exports = robot => {
nst events = ['issues.opened', 'pull_request.opened', 'issue_comment.created']
bot.on(events, context => {
return attachments(context).add({
  'title': 'Hello World',
  'title_link': 'https://example.com/hello'
})


Example

Here is a probot app that listens for a comment that matches bobby tables and adds an attachment to the comment.

t attachments = require('probot-attachments');

le.exports = robot => {
bot.on('issue_comment.created', context => {
if(context.payload.comment.body.match(/bobby tables/i)) {
  return attachments(context).add({
    'pretext': 'Let us all heed the lessons of little bobby tables:',
    'author_name': 'Bobby Tables',
    'author_link': 'https://xkcd.com/',
    'author_icon': 'http://www.codetinkerer.com/assets/little-bobby-tables.png',
    'title': 'Exploits of a Mom',
    'title_link': 'https://xkcd.com/327/',
    'text': 'Her daughter is named Help I\'m trapped in a driver\'s license factory.',
    'image_url': 'https://imgs.xkcd.com/comics/exploits_of_a_mom.png',
    'thumb_url': 'https://www.cmswire.com/~/media/59086df972604f35b46d0764cd0f1351.jpg',
    'footer': 'Probot the Trollbot',
    'footer_icon': 'https://static.comicvine.com/uploads/square_medium/8/84072/1561135-trollface.jpg',
  })
}


How it works

This extension is what you might call “a hack”. GitHub doesn't have an API for adding attachments on comments, but it does have rather large comment fields that support some HTML. This extension renders the attachment as a blockquote and appends it to the original comment body.

This extension is inspired by Slack's message attachments.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.