Skip to content

Instantly share code, notes, and snippets.

@shokai
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shokai/0b67527016fb4dcf7c9a to your computer and use it in GitHub Desktop.
Save shokai/0b67527016fb4dcf7c9a to your computer and use it in GitHub Desktop.
Circle CI Webhook for Hubot
# Description:
# Circle CI Webhook
#
# Author:
# @shokai
config =
room: "#news"
debug = require('debug')('hubot:circleci-webhook')
module.exports = (robot) ->
robot.router.post '/circleci-webhook', (req, res) ->
debug 'received /circleci-webhook'
room = req.query.room or config.room
room = "##{room}" unless /^#/.test room
status = req.body.payload?.status
subject = req.body.payload?.subject
build_url = req.body.payload?.build_url
branch = req.body.payload?.branch
reponame = req.body.payload?.reponame
username = req.body.payload?.username
unless room? and status? and subject? and build_url? and branch? and reponame? and username?
return res.status(400).end 'bad request'
res.end 'ok'
header = if status is 'failed' then ':no_good:' else ':ok_hand:'
text =
[
"#{header} [#{status.toUpperCase()}] #{subject} [#{username}/#{reponame}##{branch}]"
build_url
].join '\n'
debug text
robot.send {room: room}, text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment