Skip to content

Instantly share code, notes, and snippets.

@lawrencejones
Last active August 29, 2015 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawrencejones/81a3865659351f96502f to your computer and use it in GitHub Desktop.
Save lawrencejones/81a3865659351f96502f to your computer and use it in GitHub Desktop.
Commit hooks to insert ghi prompt and force issue reference
#!/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)()
#!/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