Skip to content

Instantly share code, notes, and snippets.

@anwinged
Created September 14, 2018 10:16
Show Gist options
  • Save anwinged/fa7276f894167799206d8b325a5e0b47 to your computer and use it in GitHub Desktop.
Save anwinged/fa7276f894167799206d8b325a5e0b47 to your computer and use it in GitHub Desktop.
#!/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