Skip to content
This repository was archived by the owner on Nov 10, 2022. It is now read-only.
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
14 changes: 14 additions & 0 deletions prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# WordPress prepare-commit-msg hook

COMMIT_EDITMSG=$1

JIRA_TASK_REGEXP='.*([A-Z]{1,32}-[0-9]{1,32}).*'
JIRA_BRANCH_REGEXP='([a-zA-Z]+-[0-9]{1,32})';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see lowercase chars in JIRA_BRANCH_REGEXP but not in JIRA_TASK_REGEXP. Is this intentional?

Also, should a ^|/ pattern mark initial delimiter for where a JIRA issue begins?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So match issues that appear like ABC-123-awesome-feature or feature/ABC-123-awesome.

if [[ ! $(cat "$COMMIT_EDITMSG") =~ $JIRA_TASK_REGEXP ]]; then
JIRA_TASK=$(git rev-parse --abbrev-ref HEAD | grep -oP "$JIRA_BRANCH_REGEXP")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the -P argument is not recognized on OSX.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, make sure to include the -E param to indicate that extended regular expressions are to be used in grep. Otherwise, the + repeater and bracket notation don't work on OSX.

if [ -n "$JIRA_TASK" ]; then
MESSAGE=`cat $COMMIT_EDITMSG`
echo "${JIRA_TASK^^}: $MESSAGE" > $COMMIT_EDITMSG
fi
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