Last active
August 29, 2015 14:02
-
-
Save lawrencejones/81a3865659351f96502f to your computer and use it in GitHub Desktop.
Commit hooks to insert ghi prompt and force issue reference
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 coffee | |
# vi: set filetype=coffee | |
fs = require 'fs' | |
ttyFd = fs.openSync '/dev/tty', 'r' | |
msgFile = process.argv[2] | |
failed = false | |
error = 'Error! Please reference git issue!' | |
spawnVim = (file, cb) -> | |
vim = (require 'child_process').spawn('vim', [file], customFds: [ttyFd,1,2]) | |
vim.on 'exit', readAndTest | |
(readAndTest = -> | |
msg = fs.readFileSync msgFile, 'utf8' | |
process.exit 0 if /^[\s\r\n]*$/.test msg.replace(/^#.*/gm, '') | |
if not /#\d+/.test msg.replace(/^#.*$/gm, '') | |
fs.appendFile msgFile, '# '+error, 'utf8' if not failed | |
console.log error | |
failed = true | |
setTimeout (-> spawnVim msgFile, readAndTest), 2500)() | |
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 coffee | |
# vi: set filetype=coffee | |
fs = require 'fs' | |
path = require 'path' | |
spawn = (require 'child_process').spawn | |
# Contains output of ghi command | |
ghiOut = '' | |
ghi = spawn 'ghi', [] | |
ghi.stdout.setEncoding 'utf8' | |
ghi.stdout.on 'data', (data) -> | |
ghiOut += data | |
ghi.on 'exit', (err) -> | |
if err is 0 | |
[msg, issues...] = ghiOut.split '\n' | |
issues = (issue.replace /^\s+(\d+)/, 'issue: #$1:\t' for issue in issues) | |
summary = ["#{msg}:"].concat(issues.map (i) -> "#\t#{i}") | |
.join '\n' | |
fs.appendFileSync process.argv[2], summary, 'utf8' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment