Created
February 25, 2015 20:48
-
-
Save GirlBossRush/23e0183ad435c971653a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var | |
fs = require('fs'), | |
messageFile = process.argv[2], | |
commitType = process.argv[3], | |
branchNameIssuePattern = /On branch .+#(\d{1,5})/, | |
issueNumber, | |
contents; | |
function messageTemplate (issueNumber) { | |
var | |
byline = '\n\n# [General description above]\n\n' + | |
'# [Details below]\n\n\n'; | |
if (issueNumber) { | |
return byline + 'Issue: #' + issueNumber + '\n'; | |
} | |
else { | |
return byline + '# WARNING: Issue number not found in branch name.\n'; | |
} | |
} | |
if (['merge', 'commit', 'message'].indexOf(commitType) !== -1) { | |
// Skip commits with existing messages. | |
process.exit(); | |
} | |
contents = fs.readFileSync(messageFile).toString(); | |
if (contents.match(/^Merge branch/)) { | |
// Skip commits resolving merge conflicts. | |
process.exit(); | |
} | |
issueNumber = (contents.match(branchNameIssuePattern) || [])[1]; | |
fs.writeFileSync(messageFile, messageTemplate(issueNumber) + contents); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment