Skip to content

Instantly share code, notes, and snippets.

@jtwalters
Created August 22, 2015 00:16
Show Gist options
  • Save jtwalters/822d7d9c524b4629fc19 to your computer and use it in GitHub Desktop.
Save jtwalters/822d7d9c524b4629fc19 to your computer and use it in GitHub Desktop.
Throw this in .git/hooks/commit-msg and chmod +x it.
#!/usr/local/bin/node
/* jshint node:true */
// This hook ensures the commit message includes [ci skip] or [ci run]
var fs = require('fs'),
spawn = require('child_process').spawn,
args = process.argv.slice(2),
filePath = args[0],
exists = fs.existsSync(filePath),
contents = exists && fs.readFileSync(filePath, "utf8"),
spawnOptions = {detached: true, stdio: 'ignore'},
say;
if (!contents) {
console.log('commit-msg hook is confused.');
process.exit(1);
}
if (!/\[ci (skip|run)\]/.test(contents)) {
console.log("No [ci skip] or [ci run] found:\n\n" + contents);
say = spawn('say', ['-r170', '-vagnes', 'compuwer says no'], spawnOptions);
process.exit(1);
}
else {
say = spawn('say', ['BOOM!!!'], spawnOptions);
process.exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment