Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 8c153b2

Browse files
authored
Fixes #1438: Project prefix contains quote characters. (#1442)
1 parent 7eaf1e0 commit 8c153b2

File tree

3 files changed

+44
-39
lines changed

3 files changed

+44
-39
lines changed

bin/blt

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $robo_namespaces = [
1414
'custom',
1515
'drupal',
1616
'frontend',
17+
'git',
1718
'setup',
1819
'tests',
1920
'vm',

scripts/git-hooks/commit-msg

+12-39
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
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
72

8-
ROOT_DIR="$(pwd)"
9-
RED='\033[0;31m'
10-
NO_COLOR='\033[0m'
3+
<?php
114

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();
156

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");
279

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+
];
3416

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';

src/Robo/Commands/Git/GitCommand.php

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Acquia\Blt\Robo\Commands\Git;
4+
5+
use Acquia\Blt\Robo\BltTasks;
6+
7+
/**
8+
* Defines commands in the "git:*" namespace.
9+
*/
10+
class GitCommand extends BltTasks {
11+
12+
/**
13+
* Validates a git commit message.
14+
*
15+
* @command git:commit-msg
16+
*/
17+
public function commitMsg($message) {
18+
$prefix = $this->getConfigValue('project.prefix');
19+
if (!preg_match("/^$prefix-[0-9]+(: )[^ ].{15,}\\./", $message)) {
20+
$this->logger->error("Invalid commit message!");
21+
$this->say("Commit messages must:");
22+
$this->say("* Contain the project prefix followed by a hyphen");
23+
$this->say("* Contain a ticket number followed by a colon and a space");
24+
$this->say("* Be at least 15 characters long and end with a period.");
25+
$this->say("Valid example: $prefix-135: Added the new picture field to the article feature.");
26+
27+
return 1;
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)