Skip to content

Instantly share code, notes, and snippets.

@AlexanderAllen
Last active January 17, 2024 13:43
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 AlexanderAllen/4358e4e2a66fe5da7cc6f5c4f88f210d to your computer and use it in GitHub Desktop.
Save AlexanderAllen/4358e4e2a66fe5da7cc6f5c4f88f210d to your computer and use it in GitHub Desktop.
Drupal contrib commit msg hook
#!/usr/bin/php
# In .git/hooks/commit-msg
# Make sure to +x hook
# https://www.atlassian.com/git/tutorials/git-hooks
# See https://www.php.net/manual/en/function.exit.php
# https://www.php.net/manual/en/reserved.variables.argv.php
# https://www.php.net/manual/en/function.file-get-contents.php
# Regex: https://regex101.com/r/uQKPeu/1
<?php
$message_file = $argv[1];
$message = file_get_contents($message_file);
$matches = [];
$result = preg_match('/^(Issue\ \#[0-9]*)(?:\N*)?:/', $message, $matches);
if ($result === 0) {
echo 'Commit message does not match pattern Issue #n '. PHP_EOL;
var_dump([$result, $matches]);
exit (1);
}
if ($result === false) {
echo 'Commit message does not match pattern Issue #n '. PHP_EOL;
var_dump([$result, $matches]);
exit (1);
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment