Permalink
Browse files

notify in chat when a new commit is pushed

  • Loading branch information...
1 parent 23a88d7 commit 6e7ce2a21fa140d935a9d2f2565893fd11a2cac4 @nesQuick nesQuick committed Aug 15, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 src/scripts/github-commits.coffee
@@ -0,0 +1,42 @@
+# Description:
+# An HTTP Listener for notifications on github pushes
+#
+# Dependencies:
+# "url": ""
+# "querystring": ""
+# "gitio": "1.0.1"
+#
+# Configuration:
+# Just put this url <HUBOT_URL>:<PORT>/hubot/gh-commits?room=<room> into you'r github hooks
+#
+# Commands:
+# None
+#
+# URLS:
+# POST /hubot/gh-commits?room=<room>[&type=<type]
+#
+# Authors:
+# nesQuick
+
+url = require('url')
+querystring = require('querystring')
+gitio = require('gitio')
+
+module.exports = (robot) ->
+
+ robot.router.post "/hubot/gh-commits", (req, res) ->
+ query = querystring.parse(url.parse(req.url).query)
+
+ res.end
+
+ user = {}
+ user.room = query.room if query.room
+ user.type = query.type if query.type
+
+ payload = JSON.parse req.body.payload
+
+ robot.send user, "Got #{payload.commits.length} new commits from #{payload.commits[0].author.name} on #{payload.repository.name}"
+ for commit in payload.commits
+ do (commit) ->
+ gitio commit.url, (err, data) ->
+ robot.send user, " * #{commit.message} (#{if err then commit.url else data})"

0 comments on commit 6e7ce2a

Please sign in to comment.