Skip to content

Instantly share code, notes, and snippets.

@vermilion1
Created January 17, 2016 16:56
Show Gist options
  • Save vermilion1/59db0ac399d545e0f756 to your computer and use it in GitHub Desktop.
Save vermilion1/59db0ac399d545e0f756 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
/**
* Hooks:
* https://www.kernel.org/pub/software/scm/git/docs/githooks.html#_prepare_commit_msg
*
* Colors:
* http://telepathy.freedesktop.org/doc/telepathy-glib/telepathy-glib-debug-ansi.html
*
* Message format:
* FECRU-7777: Message
*/
var fs = require('fs');
var args = process.argv.slice(2);
var filename = args[0];
var source = args[1];
if (source !== 'message') {
process.exit(0);
}
var TP_ANSI_RESET = '\x1b[0m';
var TP_ANSI_FG_RED = '\x1b[31m';
var TP_ANSI_FG_GREEN = '\x1b[32m';
var TP_ANSI_BOLD_ON = '\x1b[1m';
var TP_ANSI_BOLD_OFF = '\x1b[22m';
var ISSUE_KEY_RE = /^(([A-Z]+-\d+)|(NONE)): [a-zA-Z0-9]+/;
var message = fs.readFileSync(filename, 'utf8');
if (message.match(ISSUE_KEY_RE) === null) {
console.log();
console.log(TP_ANSI_FG_RED + TP_ANSI_BOLD_ON + 'ABORTING' + TP_ANSI_BOLD_OFF + TP_ANSI_RESET);
console.log(TP_ANSI_FG_RED + TP_ANSI_BOLD_ON + '--------' + TP_ANSI_BOLD_OFF + TP_ANSI_RESET);
console.log(TP_ANSI_FG_RED + 'Sorry dude, you have not specified issue key.' + TP_ANSI_RESET);
console.log(TP_ANSI_FG_RED + 'Or the key you entered is not valid. It should looks like this:' + TP_ANSI_RESET);
console.log(TP_ANSI_BOLD_ON + 'FECRU-7777: Some message' + TP_ANSI_BOLD_OFF);
console.log();
process.exit(1);
}
process.exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment