-
Notifications
You must be signed in to change notification settings - Fork 56
Simple prepare-commit-msg hook #170
base: master
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| #!/bin/bash | ||
| # WordPress prepare-commit-msg hook | ||
|
|
||
| DEV_LIB_COMMIT_MESSAGE_FILE="/tmp/.dev-lib-commit-message.$PPID" | ||
| COMMIT_EDITMSG=$1 | ||
|
|
||
| JIRA_TASK_REGEXP='.*([A-Z]{1,32}-[0-9]{1,32}).*' | ||
| JIRA_BRANCH_REGEXP='([a-zA-Z]+-[0-9]{1,32})'; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see lowercase chars in Also, should a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So match issues that appear like |
||
| if [[ ! $(cat "$COMMIT_EDITMSG") =~ $JIRA_TASK_REGEXP ]]; then | ||
| JIRA_TASK=$(git rev-parse --abbrev-ref HEAD | grep -oP "$JIRA_BRANCH_REGEXP") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, make sure to include the |
||
| if [ -n "$JIRA_TASK" ]; then | ||
| MESSAGE=`cat $COMMIT_EDITMSG` | ||
| echo "${JIRA_TASK^^}: $MESSAGE" > $COMMIT_EDITMSG | ||
| fi | ||
| fi | ||
|
|
||
| if [ -f "$DEV_LIB_COMMIT_MESSAGE_FILE" ]; then | ||
| cat "$DEV_LIB_COMMIT_MESSAGE_FILE" >> $COMMIT_EDITMSG | ||
| unlink "$DEV_LIB_COMMIT_MESSAGE_FILE" | ||
| fi | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcin-lawrowski instead of appending to a variable, how about just appending it to the file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When pre-commit terminates with return code other than 0 the file should be cleaned as well. In this approach the file is created only if all tests passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but I don't think that's so important now, since the file is getting stored in
/tmp. It will automatically get garbage-collected with the next reboot.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, I wasn't aware that Bash supported the
+=operator. Thanks for enlightening me 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pleasure is all mine ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Temporary files will be garbage-collected with the next reboot, but what about users that use this tool in some server environment which isn't rebooted often?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The files are super tiny, so I'm not so concerned about it, since this is going to be used on dev environments not servers. Also, there are a lot of other files being written to
/tmpwhen running thepre-commithook and Travis CI builds (see usages ofTEMP_DIRECTORYin https://github.com/xwp/wp-dev-lib/blob/master/check-diff.sh).