Skip to content

Instantly share code, notes, and snippets.

@foo9
Last active August 29, 2015 14:21
Show Gist options
  • Save foo9/0a83c4a68f5f7d8ec00e to your computer and use it in GitHub Desktop.
Save foo9/0a83c4a68f5f7d8ec00e to your computer and use it in GitHub Desktop.
hubot script
module.exports = (robot) ->
SPACE_KEY = '!! HERE IS YOUR SPACE KEY !!'
BACKLOG_API_KEY = '!! HERE IS YOUR BACKLOG API KEY !!'
robot.hear ///https:\/\/#{SPACE_KEY}\.backlog\.jp\/view\/([a-zA-Z0-9_\-]+)#comment\-(\d+)///, (msg) ->
commentUrl = msg.match[0]
issueIdOrKey = msg.match[1]
commentId = msg.match[2]
if issueIdOrKey and commentId
getCommentApiUrl = "https://#{SPACE_KEY}.backlog.jp/api/v2/issues/#{issueIdOrKey}/comments/#{commentId}"
getIssueApiUrl = "https://#{SPACE_KEY}.backlog.jp/api/v2/issues/#{issueIdOrKey}"
msg.http(getIssueApiUrl)
.query(apiKey: BACKLOG_API_KEY)
.get() (err, res, body) ->
if not err and res.statusCode is 200
issue = JSON.parse body
msg.http(getCommentApiUrl)
.query(apiKey: BACKLOG_API_KEY)
.get() (err, res, body) ->
if not err and res.statusCode is 200
comment = JSON.parse body
payload =
message: msg.message
content:
text: comment.content.replace(/\n/g, '\n')
pretext: issue.summary
title: commentUrl
title_link: commentUrl
fallback: comment.content
color: '#93c400'
robot.emit 'slack-attachment', payload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment