diff --git a/check-diff.sh b/check-diff.sh index f3e89f5..7f76b1f 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 { @@ -685,6 +686,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 +703,7 @@ function lint_js_files { fi fi ) + append_commit_message "JSHint Check" "Passed" fi # Run JSCS. @@ -717,6 +720,7 @@ function lint_js_files { fi fi ) + append_commit_message "JSCS Check" "Passed" fi # Run ESLint. @@ -737,6 +741,7 @@ function lint_js_files { fi fi ) + append_commit_message "ESLint Check" "Passed" fi } @@ -765,6 +770,8 @@ function run_qunit { grunt qunit cd - /dev/null + + append_commit_message "QUnit Tests" "Passed" done } @@ -780,6 +787,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 { @@ -796,6 +804,7 @@ function lint_php_files { php -lf "$php_file" done ) + 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 @@ -815,6 +824,13 @@ function lint_php_files { fi fi ) + STANDARD="$( if [ ! -z "$PHPCS_RULESET_FILE" ]; then echo "$PHPCS_RULESET_FILE"; else echo "$WPCS_STANDARD"; fi )" + if [ -e "$STANDARD" ]; then + STANDARD_VERSION=$(basename $STANDARD) + append_commit_message "PHP_CodeSniffer $STANDARD_VERSION Check" "Passed" + else + append_commit_message "PHP_CodeSniffer $STANDARD Check" "Passed" + fi fi } diff --git a/pre-commit b/pre-commit index 7a89f85..552ee4e 100755 --- a/pre-commit +++ b/pre-commit @@ -19,6 +19,20 @@ 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" +if [ -e "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then + unlink "$DEV_LIB_COMMIT_MESSAGE_FILE" +fi +function append_commit_message { + LABEL=$1 + VALUE=$2 + 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" set_environment_variables --diff-base ${DIFF_BASE:-HEAD} --diff-head ${DIFF_HEAD:-STAGE} install_tools 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).