Created
September 14, 2018 10:16
-
-
Save anwinged/fa7276f894167799206d8b325a5e0b47 to your computer and use it in GitHub Desktop.
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 php | |
<?php | |
list(, $file, $source) = array_pad($argv, 3, ''); | |
if ($source !== '' && $source !== 'message') { | |
exit(0); | |
} | |
$branch = `git symbolic-ref --short HEAD`; | |
if (!preg_match('/^[bft]?(?<issue>\d+)/', $branch, $matches)) { | |
exit(0); | |
} | |
$prefix = "[#{$matches['issue']}] "; | |
$pattern = '/^\[#\d+\] /'; | |
$contents = file_get_contents($file); | |
if (!preg_match($pattern, $contents)) { | |
file_put_contents($file, $prefix.$contents); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment