Skip to content

Instantly share code, notes, and snippets.

@king-panda
Last active August 29, 2015 14:17
Show Gist options
  • Save king-panda/013f3b1910d2b87a0ff3 to your computer and use it in GitHub Desktop.
Save king-panda/013f3b1910d2b87a0ff3 to your computer and use it in GitHub Desktop.
【Hubot】BacklogからHubotを経由してChatworkに課題の操作を通知 ref: http://qiita.com/kingpanda/items/4de3c40ed615941bbd5f
backlogUrl = 'https://XXXXX.backlog.jp/'
module.exports = (robot) ->
robot.router.post "/room/:room", (req, res) ->
room = req.params.room
body = req.body
console.log 'body type = ' + body.type
console.log 'room = ' + room
try
switch body.type
when 1
label = '課題が追加'
when 2, 3
label = '課題が更新'
when 4
label = '課題が削除'
else
return
url = "#{backlogUrl}view/#{body.project.projectKey}-#{body.content.key_id}"
if body.content.comment?.id?
url += "#comment-#{body.content.comment.id}"
message = "[info][title]Backlogより[/title]"
message += "#{body.createdUser.name}さんによって#{label}されました\n"
message += "[#{body.project.projectKey}-#{body.content.key_id}]"
message += "#{body.content.summary}\n"
if body.content.comment?.content?
message += "#{body.content.comment.content}\n"
message += "#{url}[/info]"
console.log 'message = ' + message
if message?
robot.messageRoom room, message
res.end "OK"
else
robot.messageRoom room, "Backlog integration error."
res.end "Error"
catch error
robot.send
res.end "Error"
http://<Hubotのホスト名>/room/<ChatworkのルームID>
[
{
"id": 3153,
"project": {
"id": 92,
"projectKey": "SUB",
"name": "サブタスク",
"chartEnabled": true,
"subtaskingEnabled": true,
"textFormattingRule": null,
"archived": false,
"displayOrder": 0
},
"type": 2,
"content": {
"id": 4809,
"key_id": 121,
"summary": "コメント",
"description": "",
"comment": {
"id": 7237,
"content": ""
},
"changes": [
{
"field": "milestone",
"new_value": "R2014-07-23",
"old_value": "",
"type": "standard"
},
{
"field": "status",
"new_value": "4",
"old_value": "1",
"type": "standard"
}
]
},
"notifications": [
{
"id": 25,
"alreadyRead": false,
"reason": 2,
"user": {
"id": 5686,
"userId": "takada",
"name": "takada",
"roleType": 2,
"lang": "ja",
"mailAddress": "takada@nulab.example"
}
"resourceAlreadyRead":false
},
],
"createdUser": {
"id": 1,
"userId": "admin",
"name": "admin",
"roleType": 1,
"lang": "ja",
"mailAddress": "eguchi@nulab.example"
},
"created": "2013-12-27T07:50:44Z"
},
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment