Skip to content

Instantly share code, notes, and snippets.

@BastienClement
Created September 18, 2018 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BastienClement/7c69fc78ead6abc45058f3815e2bcbcb to your computer and use it in GitHub Desktop.
Save BastienClement/7c69fc78ead6abc45058f3815e2bcbcb to your computer and use it in GitHub Desktop.
Git ticket ref hook
#!/usr/bin/env php
<?php
$REF_PATTERN = "[A-Z]{3,}-\\d+";
$branch = exec("git rev-parse --abbrev-ref HEAD");
if (preg_match("/(bug|feature)\\/($REF_PATTERN)/", $branch, $matches)) {
$msg = file_get_contents($argv[1]);
$ticket = $matches[2];
if (!preg_match("/\\[.*?$REF_PATTERN.*?\\]/", $msg)) {
file_put_contents($argv[1], "\n\nTicket: [$ticket]\n", FILE_APPEND);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment