From 20ec4355450041feddba5bcd3adfb49d3bb1903e Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Tue, 2 Aug 2016 13:43:50 -0400 Subject: [PATCH 1/2] Resolves #249: Adding yaml parser to git-commit hook. --- template/scripts/git-hooks/commit-msg | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/template/scripts/git-hooks/commit-msg b/template/scripts/git-hooks/commit-msg index e37106282..1e0c74a0e 100755 --- a/template/scripts/git-hooks/commit-msg +++ b/template/scripts/git-hooks/commit-msg @@ -5,12 +5,16 @@ # You may adapt the message length check. Currently checking it's longer than # 15 characters. -regex="^${project.prefix}-[0-9]+(: )[^ ].{15,}\." + +GIT_ROOT=$(git rev-parse --show-toplevel) +PREFIX=$($GIT_ROOT/../../vendor/bin/drupal yaml:get:value $GIT_ROOT/project.yml project.prefix) + +regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\." if ! grep -iqE "$regex" "$1"; then echo "Invalid commit message. Commit messages must:" echo "* Contain the project prefix followed by a hyphen" echo "* Contain a ticket number followed by a colon and a space" echo "* Be at least 15 characters long and end with a period." - echo "Valid example: ${project.prefix}-135: Added the new picture field to the article feature." + echo "Valid example: $PREFIX-135: Added the new picture field to the article feature." exit 1; fi From b9351d244da7583b7185c47e7672da00756eba4d Mon Sep 17 00:00:00 2001 From: Matthew Grasmick Date: Wed, 3 Aug 2016 13:07:54 -0400 Subject: [PATCH 2/2] Fixing root reference. --- template/scripts/git-hooks/commit-msg | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/template/scripts/git-hooks/commit-msg b/template/scripts/git-hooks/commit-msg index 1e0c74a0e..2a280f93d 100755 --- a/template/scripts/git-hooks/commit-msg +++ b/template/scripts/git-hooks/commit-msg @@ -6,9 +6,8 @@ # 15 characters. -GIT_ROOT=$(git rev-parse --show-toplevel) -PREFIX=$($GIT_ROOT/../../vendor/bin/drupal yaml:get:value $GIT_ROOT/project.yml project.prefix) - +ROOT_DIR="$(pwd)/" +PREFIX=$($ROOT_DIR/vendor/bin/drupal yaml:get:value $ROOT_DIR/project.yml project.prefix) regex="^${PREFIX}-[0-9]+(: )[^ ].{15,}\." if ! grep -iqE "$regex" "$1"; then echo "Invalid commit message. Commit messages must:"