LoginSignup
20
19

More than 5 years have passed since last update.

gitbucket→hubot→slack連携

Last updated at Posted at 2015-04-10

backlog→hubot→slack連携
http://qiita.com/yo-iida/items/c69fe7b6afb2c082b822

からの派生で、gitbucketのwebhookも下記のようなソースコードで、
簡単にslackに連携できる。

reqで受け取ったリクエスト情報の中から、
必要な情報をパースしてmessageに整形して、
slackに投げるというそれだけなので、
必要に応じてコピペでいろいろな連携botがつくれます。

gitbucket-notification.coffee
# Description:
#   gitbucket to Slack
#
# Commands:
#   None

module.exports = (robot) ->
  robot.router.post "/gitbucket-to-slack/:room", (req, res) ->
    { room } = req.params
    { body } = req

    try

      if body.payload

        json = JSON.parse body.payload

        message = "==== commit info ====\n"
        message += "timestamp: #{json.commits[0].timestamp}\n"
        message += "id: #{json.commits[0].id}\n"
        message += "author: #{json.commits[0].author.name}<#{json.commits[0].author.email}>\n"
        message += "message: #{json.commits[0].message}\n"
        message += "url: #{json.commits[0].url}\n"

        if message?
            robot.messageRoom room, message
            res.end "OK"
        else
            robot.messageRoom room, "gitbucket integration error."
            res.end "Error"
    catch error
      robot.send
      res.end "Error"

20
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
20
19