From a22b1615efca1c04a12294647054c06f02dd8b39 Mon Sep 17 00:00:00 2001 From: Marcin Lawrowski Date: Sat, 23 Apr 2016 11:53:44 +0100 Subject: [PATCH 1/5] Status checks in commit message --- check-diff.sh | 1 + pre-commit | 10 ++++++++++ prepare-commit-msg | 11 +++++++++++ readme.md | 7 +++++++ 4 files changed, 29 insertions(+) create mode 100755 prepare-commit-msg diff --git a/check-diff.sh b/check-diff.sh index f3e89f5..2b76076 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -780,6 +780,7 @@ function lint_xml_files { cd "$LINTING_DIRECTORY" cat "$TEMP_DIRECTORY/paths-scope-xml" | remove_diff_range | xargs xmllint --noout ) + append_commit_message "Xmllint Check" "Passed" } function lint_php_files { diff --git a/pre-commit b/pre-commit index 7a89f85..ef264b3 100755 --- a/pre-commit +++ b/pre-commit @@ -19,6 +19,14 @@ if [ ! -e "$DEV_LIB_PATH/check-diff.sh" ]; then exit 1 fi +DEV_LIB_COMMIT_MESSAGE_FILE="/tmp/.dev-lib-commit-message.$PPID" +DEV_LIB_COMMIT_MESSAGE='' +function append_commit_message { + LABEL=$1 + VALUE=$2 + DEV_LIB_COMMIT_MESSAGE+="\n$LABEL: $VALUE" +} + source "$DEV_LIB_PATH/check-diff.sh" set_environment_variables --diff-base ${DIFF_BASE:-HEAD} --diff-head ${DIFF_HEAD:-STAGE} install_tools @@ -41,3 +49,5 @@ if [[ $SYNC_README_MD == 1 ]] && [ -e readme.txt ] && cat "$TEMP_DIRECTORY/paths git add $MARKDOWN_README_PATH fi fi + +echo -e "$DEV_LIB_COMMIT_MESSAGE" > $DEV_LIB_COMMIT_MESSAGE_FILE diff --git a/prepare-commit-msg b/prepare-commit-msg new file mode 100755 index 0000000..c26f283 --- /dev/null +++ b/prepare-commit-msg @@ -0,0 +1,11 @@ +#!/bin/bash +# WordPress prepare-commit-msg hook + +DEV_LIB_COMMIT_MESSAGE_FILE="/tmp/.dev-lib-commit-message.$PPID" +COMMIT_EDITMSG=$1 + +if [ -f "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then + cat "$DEV_LIB_COMMIT_MESSAGE_FILE" >> $COMMIT_EDITMSG + unlink "$DEV_LIB_COMMIT_MESSAGE_FILE" +fi + diff --git a/readme.md b/readme.md index 436a950..9f0daac 100644 --- a/readme.md +++ b/readme.md @@ -27,6 +27,12 @@ To install the pre-commit hook, symlink to [`pre-commit`](pre-commit) from your cd .git/hooks && ln -s ../../dev-lib/pre-commit . && cd - ``` +To install the prepare-commit-msg hook, symlink to [`prepare-commit-msg`](prepare-commit-msg) from your project's `.git/hooks/prepare-commit-msg`: + +```bash +cd .git/hooks && ln -s ../../dev-lib/prepare-commit-msg . && cd - +``` + Also symlink (or copy) the [`.jshintrc`](.jshint), [`.jshintignore`](.jshintignore), [`.jscsrc`](.jscsrc), [`phpcs.ruleset.xml`](phpcs.ruleset.xml), and [`phpunit-plugin.xml`](phpunit-plugin.xml) (note the PHPUnit config will need its paths modified if it is copied instead of symlinked): ```bash @@ -48,6 +54,7 @@ Often installing as a submodule is not viable, for example when contributing to git clone https://github.com/xwp/wp-dev-lib.git ~/Projects/wp-dev-lib cd my-plugin/.git/hooks ln -s ~/Projects/wp-dev-lib/pre-commit +ln -s ~/Projects/wp-dev-lib/prepare-commit-msg ``` For the Travis CI checks, the `.travis.yml` copied and committed to the repo (see below) will clone the repo into the `dev-lib` directory if it doesn't exist (or whatever your `DEV_LIB_PATH` environment variable is set to). From 90bd64a8ac29553f85aa0862aa647b6d9c5bc08b Mon Sep 17 00:00:00 2001 From: Marcin Lawrowski Date: Sat, 23 Apr 2016 13:35:12 +0100 Subject: [PATCH 2/5] Add next commit messages --- check-diff.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/check-diff.sh b/check-diff.sh index 2b76076..69c5f21 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -685,6 +685,7 @@ function lint_js_files { cd "$LINTING_DIRECTORY" cat "$TEMP_DIRECTORY/paths-scope-js" | remove_diff_range | xargs java -jar "$YUI_COMPRESSOR_PATH" --nomunge --disable-optimizations -o /dev/null 2>&1 ) + append_commit_message "YUI Compressor" "Done" fi # Run JSHint. @@ -701,6 +702,7 @@ function lint_js_files { fi fi ) + append_commit_message "JSHint Check" "Passed" fi # Run JSCS. @@ -717,6 +719,7 @@ function lint_js_files { fi fi ) + append_commit_message "JSCS Check" "Passed" fi # Run ESLint. @@ -737,6 +740,7 @@ function lint_js_files { fi fi ) + append_commit_message "ESLint Check" "Passed" fi } @@ -797,6 +801,7 @@ function lint_php_files { php -lf "$php_file" done ) + append_commit_message "PHP $(php -v | grep -Eo 'PHP [0-9]+(\.[0-9]+)*') Syntax Check" "Passed" # Check PHP_CodeSniffer WordPress-Coding-Standards. if [ "$( type -t phpcs )" != '' ] && ( [ -n "$WPCS_STANDARD" ] || [ -n "$PHPCS_RULESET_FILE" ] ) && ! grep -sqi 'phpcs' <<< "$DEV_LIB_SKIP"; then @@ -816,6 +821,7 @@ function lint_php_files { fi fi ) + append_commit_message "PHP_CodeSniffer Check" "Passed" fi } From 5181c34d70d0a0e9876882c95c0aab88af87940e Mon Sep 17 00:00:00 2001 From: Marcin Lawrowski Date: Tue, 26 Apr 2016 08:04:02 +0100 Subject: [PATCH 3/5] Append messages directly to the file --- pre-commit | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pre-commit b/pre-commit index ef264b3..552ee4e 100755 --- a/pre-commit +++ b/pre-commit @@ -19,12 +19,18 @@ if [ ! -e "$DEV_LIB_PATH/check-diff.sh" ]; then exit 1 fi +# The following file is used in prepare-commit-msg hook: DEV_LIB_COMMIT_MESSAGE_FILE="/tmp/.dev-lib-commit-message.$PPID" -DEV_LIB_COMMIT_MESSAGE='' +if [ -e "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then + unlink "$DEV_LIB_COMMIT_MESSAGE_FILE" +fi function append_commit_message { LABEL=$1 VALUE=$2 - DEV_LIB_COMMIT_MESSAGE+="\n$LABEL: $VALUE" + if [ ! -e "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then + echo -e "" >> $DEV_LIB_COMMIT_MESSAGE_FILE + fi + echo -e "$LABEL: $VALUE" >> $DEV_LIB_COMMIT_MESSAGE_FILE } source "$DEV_LIB_PATH/check-diff.sh" @@ -49,5 +55,3 @@ if [[ $SYNC_README_MD == 1 ]] && [ -e readme.txt ] && cat "$TEMP_DIRECTORY/paths git add $MARKDOWN_README_PATH fi fi - -echo -e "$DEV_LIB_COMMIT_MESSAGE" > $DEV_LIB_COMMIT_MESSAGE_FILE From daae16f8a5bd27a103ec39fb978f52fe9384deba Mon Sep 17 00:00:00 2001 From: Marcin Lawrowski Date: Tue, 26 Apr 2016 09:48:43 +0100 Subject: [PATCH 4/5] Include other checks --- check-diff.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/check-diff.sh b/check-diff.sh index 69c5f21..dc83af0 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -593,6 +593,7 @@ function run_phpunit_local { echo "Skipping phpunit since not installed or WP_TESTS_DIR env missing" fi ) + append_commit_message "PHPUnit Tests" "Passed" } function run_phpunit_travisci { @@ -801,7 +802,7 @@ function lint_php_files { php -lf "$php_file" done ) - append_commit_message "PHP $(php -v | grep -Eo 'PHP [0-9]+(\.[0-9]+)*') Syntax Check" "Passed" + append_commit_message "$(php -v | grep -Eo 'PHP [0-9]+(\.[0-9]+)*') Syntax Check" "Passed" # Check PHP_CodeSniffer WordPress-Coding-Standards. if [ "$( type -t phpcs )" != '' ] && ( [ -n "$WPCS_STANDARD" ] || [ -n "$PHPCS_RULESET_FILE" ] ) && ! grep -sqi 'phpcs' <<< "$DEV_LIB_SKIP"; then @@ -821,7 +822,13 @@ function lint_php_files { fi fi ) - append_commit_message "PHP_CodeSniffer Check" "Passed" + STANDARD="$( if [ ! -z "$PHPCS_RULESET_FILE" ]; then echo "$PHPCS_RULESET_FILE"; else echo "$WPCS_STANDARD"; fi )" + if [ -e "$STANDARD" ]; then + STANDARD_VERSION=$(echo 'cat //ruleset/rule/@ref' | xmllint --shell phpcs.ruleset.xml | awk -F'[="]' '!/>/{print $(NF-1)}') + append_commit_message "PHP_CodeSniffer $STANDARD_VERSION Check" "Passed" + else + append_commit_message "PHP_CodeSniffer $STANDARD Check" "Passed" + fi fi } From cfc03ff4c348163a30852376670570140c47c54e Mon Sep 17 00:00:00 2001 From: Marcin Lawrowski Date: Thu, 28 Apr 2016 15:02:55 +0100 Subject: [PATCH 5/5] Filename for the PHPCS ruleset in commit message --- check-diff.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/check-diff.sh b/check-diff.sh index dc83af0..7f76b1f 100755 --- a/check-diff.sh +++ b/check-diff.sh @@ -770,6 +770,8 @@ function run_qunit { grunt qunit cd - /dev/null + + append_commit_message "QUnit Tests" "Passed" done } @@ -824,7 +826,7 @@ function lint_php_files { ) STANDARD="$( if [ ! -z "$PHPCS_RULESET_FILE" ]; then echo "$PHPCS_RULESET_FILE"; else echo "$WPCS_STANDARD"; fi )" if [ -e "$STANDARD" ]; then - STANDARD_VERSION=$(echo 'cat //ruleset/rule/@ref' | xmllint --shell phpcs.ruleset.xml | awk -F'[="]' '!/>/{print $(NF-1)}') + STANDARD_VERSION=$(basename $STANDARD) append_commit_message "PHP_CodeSniffer $STANDARD_VERSION Check" "Passed" else append_commit_message "PHP_CodeSniffer $STANDARD Check" "Passed"