JIRAのMentionコメントをSlackのDMで通知するスクリプト
追記(2015/05/19)
このまま使うには一度botとDMのやりとりをしておく必要があります。
はじめに
JIRAのコメントの通知がメールでしか来ないと見逃すし、Slackに流れてきたら楽なのにって思ったので作った。
使い方
- JIRAのWebHooksに
[your heroku app url]/hubot/jira-comment-dm
のURLを登録し、issueのupdatedだけチェックを入れておく。 - JIRAのURLを
heroku config:add HUBOT_JIRA_URL=[your jira url]
で環境変数に登録しておく。 - (必要であれば)JIRAのハンドルネームとSlackのハンドルネームが異なる場合はmapに登録しておく。
サンプル
こんな感じでDMが届く。仕事しろって言われてる。
# Description: # hubot monitoring jira comments mention and slack DM # # Dependencies: # None # # Configuration: # HUBOT_JIRA_URL # # Commands: # None # # Author: # futabooo # Use if the user name of jira and slack is different # "jiraName": "slackName" map = module.exports = (robot) -> convertHandleName = (name) -> map[name] || name extractHandleName = (body) -> temp = body.match(/\[~.+?]/g) unless temp is null name = [] for i in temp name.push("#{i}".replace(/[\[~\]]/g, "")) return name robot.router.post '/hubot/jira-comment-dm', (req, res) -> body = req.body if body.webhookEvent == 'jira:issue_updated' && body.comment issue = "#{body.issue.key} #{body.issue.fields.summary}" url = "#{process.env.HUBOT_JIRA_URL}/browse/#{body.issue.key}" handleNameList = extractHandleName(body.comment.body) unless handleNameList is null for i in handleNameList robot.send(room: convertHandleName(i), "*#{issue}* _(#{url})_\n@#{body.comment.author.name}'s comment:\n```#{body.comment.body}```") res.send 'OK'
さいごに
正規表現力が低くて一発で名前を抜けてないけど、動いてるから運用上問題ないと思われる。 人が増えたら超大変だろうなぁと思ってる。