Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Javascript (node, iojs) port of subversion.pl
Browse files Browse the repository at this point in the history
This implements a simple post-commit hook script in javascript that will notify slack's subversion integration.
  • Loading branch information
nitriques committed Feb 16, 2015
1 parent 2734411 commit f612da4
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions subversion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
'use strict';

/*
Call this script from a post-commit.[bat|sh]
Unix:
node /path/topost-commit.js $1 $2 $3 $4
Windows:
node C:\path\to\post-commit.js %1 %2 %3 %4
Need node 0.12+ or iojs 1.0+
*/

try {
var token = 'xxxxx'; // replace with yours
var domain = 'xxxxx.slack.com'; // replace with yours
var rev = parseInt(process.argv[3], 10);
var path = process.argv[2];

var child = require('child_process');

var log = child.execSync('svnlook log -r ' + rev + ' ' + path, {encoding: 'utf8'}).replace(/[\r\n]/gm, '');
var author = child.execSync('svnlook author -r ' + rev + ' ' + path, {encoding: 'utf8'}).replace(/[\r\n]/gm, '');

var payload = JSON.stringify({
revision: rev,
url: 'https://server/!/#repo/commit/r' + rev, // change for yours
author: author,
log: log,
color: 'good'
});

console.log(payload);

var http = require('https');

var req = http.request({
hostname: domain,
path: '/services/hooks/subversion?token=' + token,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
accept: 'application/json'
}
}, function (res, data) {
res.setEncoding('utf8');
console.log(res.statusCode);
console.log(res.headers);
res.on('data', function (chunk) {
console.log(chunk);
});
res.on('end', function () {
//console.log('end');
});
});

req.write('payload=' + payload);
req.end();
} catch (ex) {
console.log(ex.message);
}

0 comments on commit f612da4

Please sign in to comment.