Created
December 4, 2013 03:42
-
-
Save vseryakov/7781984 to your computer and use it in GitHub Desktop.
bitbucket hook to hipchat commit message
This file contains 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
#!/usr/bin/env node | |
var url = require('url'); | |
var https = require('https'); | |
var qs = require('querystring'); | |
var data = ""; | |
process.stdin.resume(); | |
process.stdin.on('data', function (chunk) { data += String(chunk); }); | |
process.stdin.on('end', function() { | |
var msg = JSON.parse(data); | |
msg.commits.forEach(function(commit) { | |
var text = "Commit in <a href=" + msg.canon_url + msg.repository.absolute_url + ">" + msg.repository.name + "</a>:<br>" + | |
String(commit.message).replace("\n", "<br>"); | |
var post = qs.stringify({ room_id: "ROOM_ID_OR_NAME", | |
from: commit.author, | |
color: "green", | |
messageformat: "html", | |
message: text }); | |
var options = url.parse("https://api.hipchat.com/v1/rooms/message?auth_token=API_TOKEN"); | |
options.method = 'POST'; | |
options.headers = { 'Content-Type': 'application/x-www-form-urlencoded', | |
'Content-Length': post.length }; | |
var req = https.request(options, function(res) { | |
res.on('data', function(d) { process.stdout.write(d); }); | |
}); | |
req.end(post); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment