This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Javascript (node, iojs) port of subversion.pl
This implements a simple post-commit hook script in javascript that will notify slack's subversion integration.
- Loading branch information
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
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
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); | ||
} |