Created
January 19, 2013 23:19
-
-
Save ZeroStride/4575776 to your computer and use it in GitHub Desktop.
GitHub post-commit hook that posts to Carrot.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var express = require('express'); | |
| var crypto = require('crypto'); | |
| var carrot = require('./Carrot.min.js'); | |
| var carrotAppId = process.env.FACEBOOK_APP_ID; | |
| var carrotAppSecret = process.env.CARROT_SECRET; | |
| var app = express.createServer(express.logger()); | |
| app.use(express.bodyParser()); | |
| app.get('/user/:id', function(request, response) { | |
| var id = request.params.id; | |
| var theCarrot = new carrot.Carrot(carrotAppId, id, carrotAppSecret); | |
| theCarrot.createUser(request.query['access_token'], function(statusCode) { | |
| response.send(statusCode); | |
| }); | |
| }); | |
| app.post('/', function(request, response) { | |
| var theCarrot = new carrot.Carrot(carrotAppId, null, carrotAppSecret); | |
| var payload = JSON.parse(request.body.payload); | |
| setTimeout(function(){ | |
| for (var i = 0; i < payload.commits.length; i++) { | |
| var commit = payload.commits[i]; | |
| var md5sum = crypto.createHash('md5'); | |
| var short_sha = commit.id.slice(0, 7); | |
| md5sum.update(commit.author.email, 'utf8'); | |
| theCarrot.udid = commit.author.username; | |
| theCarrot.postAction('push', null, {}, { | |
| 'object_type': 'commit', | |
| 'title': short_sha, | |
| 'identifier': short_sha, | |
| 'image_url': "http://www.gravatar.com/avatar/" + md5sum.digest('hex').toLowerCase(), | |
| 'fields': {'sha': short_sha}, | |
| 'description': commit.message | |
| }); | |
| } | |
| }, 300000); // Send 5 minutes later | |
| response.send("OK", 200); | |
| }); | |
| var port = process.env.PORT || 5000; | |
| app.listen(port, function() { | |
| console.log("Listening on " + port); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment