|
1 |
| -#!/usr/bin/env bash |
2 |
| -# |
3 |
| -# To enable this hook, developers should place it in .git/hooks/. |
4 |
| -# |
5 |
| -# You may adapt the message length check. Currently checking it's longer than |
6 |
| -# 15 characters. |
| 1 | +#!/usr/bin/env php |
7 | 2 |
|
8 |
| -ROOT_DIR="$(pwd)" |
9 |
| -RED='\033[0;31m' |
10 |
| -NO_COLOR='\033[0m' |
| 3 | +<?php |
11 | 4 |
|
12 |
| -# yaml-cli commands. |
13 |
| -COMMAND_LOCAL="$ROOT_DIR/vendor/bin/yaml-cli get:value $ROOT_DIR/blt/project.local.yml project.prefix" |
14 |
| -COMMAND_MASTER="$ROOT_DIR/vendor/bin/yaml-cli get:value $ROOT_DIR/blt/project.yml project.prefix" |
| 5 | +$repo_root = getcwd(); |
15 | 6 |
|
16 |
| -# Attempt to load project.prefix from the local file. Run the command and check |
17 |
| -# its return value. |
18 |
| -COMMAND_RET=$(${COMMAND_LOCAL}) |
19 |
| -if [ $? -eq 0 ]; then |
20 |
| - # There were no errors, use the project.local.yml prefix value. |
21 |
| - PREFIX=${COMMAND_RET} |
22 |
| -else |
23 |
| - # Loading from local file returned an error. The file either does not exist |
24 |
| - # or does not have a value for project.prefix, load from the master file. |
25 |
| - PREFIX=$(${COMMAND_MASTER}) |
26 |
| -fi |
| 7 | +$original_argv = $_SERVER['argv']; |
| 8 | +$commit_msg = rtrim(file_get_contents($original_argv[1]), "\n"); |
27 | 9 |
|
28 |
| -# Make sure there were no errors while running the yaml-cli command. |
29 |
| -if [ $? -ne 0 ]; then |
30 |
| - printf "${RED}Error: could not get project prefix!${NO_COLOR} Please check:\n" |
31 |
| - echo "* Project prefix is set properly in project.yml." |
32 |
| - exit 1; |
33 |
| -fi |
| 10 | +// Construct pseudo `blt commit-msg $commit_msg` call. |
| 11 | +$_SERVER['argv'] = [ |
| 12 | + $repo_root . '/bin/blt-robo', |
| 13 | + 'git:commit-msg', |
| 14 | + $commit_msg, |
| 15 | +]; |
34 | 16 |
|
35 |
| -# Validate the commit message. |
36 |
| -regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\." |
37 |
| -if ! grep -iqE "$regex" "$1"; then |
38 |
| - printf "${RED}Error: invalid commit message!${NO_COLOR} Commit messages must:\n" |
39 |
| - echo "* Contain the project prefix followed by a hyphen" |
40 |
| - echo "* Contain a ticket number followed by a colon and a space" |
41 |
| - echo "* Be at least 15 characters long and end with a period." |
42 |
| - echo "Valid example: $PREFIX-135: Added the new picture field to the article feature." |
43 |
| - exit 1; |
44 |
| -fi |
| 17 | +require __DIR__ . '/../../bin/blt-robo-run.php'; |
0 commit comments