Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Status checks in commit message #171

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions check-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand All @@ -701,6 +703,7 @@ function lint_js_files {
fi
fi
)
append_commit_message "JSHint Check" "Passed"
fi

# Run JSCS.
Expand All @@ -717,6 +720,7 @@ function lint_js_files {
fi
fi
)
append_commit_message "JSCS Check" "Passed"
fi

# Run ESLint.
Expand All @@ -737,6 +741,7 @@ function lint_js_files {
fi
fi
)
append_commit_message "ESLint Check" "Passed"
fi
}

Expand Down Expand Up @@ -765,6 +770,8 @@ function run_qunit {
grunt qunit

cd - /dev/null

append_commit_message "QUnit Tests" "Passed"
done
}

Expand All @@ -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 {
Expand All @@ -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
Expand All @@ -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
}

Expand Down
14 changes: 14 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -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

7 changes: 7 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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).
Expand Down