Skip to content

Commit

Permalink
🤖 config(husky): Configure commit-msg hook.
Browse files Browse the repository at this point in the history
These changes were automatically generated by a transform whose code can be found at:
  - https://github.com/aureooms/rejuvenate/blob/a5a57b70ac6fd6fb77fdab32e6b7be7519ce9564/src/transforms/husky:hook-configure-commit-msg.js
Please contact the author of the transform if you believe there was an error.
  • Loading branch information
a-flying-potato authored and make-github-pseudonymous-again committed Mar 17, 2021
1 parent 2151cba commit 850eabe
Show file tree
Hide file tree
Showing 4 changed files with 400 additions and 22 deletions.
3 changes: 3 additions & 0 deletions .commitlintrc.js
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@js-library']
};
52 changes: 52 additions & 0 deletions .husky/commit-msg
@@ -0,0 +1,52 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

function ask () {

# This is a general-purpose function to ask Yes/No questions in Bash, either
# with or without a default answer. It keeps repeating the question until it
# gets a valid answer.

# http://djm.me/ask

if [ "${2:-}" = "Y" ]; then
prompt="Y/n"
default=Y
elif [ "${2:-}" = "N" ]; then
prompt="y/N"
default=N
else
prompt="y/n"
default=
fi

while true; do

# Ask the question (not using "read -p" as it uses stderr not stdout)
echo -n "$1 [$prompt] "

# Read the answer (use /dev/tty in case stdin is redirected from somewhere else)
read REPLY </dev/tty

# Default?
if [ -z "$REPLY" ]; then
REPLY=$default
fi

# Check if the reply is valid
case "$REPLY" in
Y*|y*) return 0 ;;
N*|n*) return 1 ;;
esac

done

}

while ! npm run commit-msg -- "$1" ; do
if [ -t 1 ] && ask 'There was an error. Do you wish to amend your commit message?' Y ; then
${GIT_EDITOR:-$EDITOR} "$1" < /dev/tty
else
exit 1
fi
done
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -35,6 +35,7 @@
"build": "rm -rf lib && babel src -d lib",
"build-docs": "esdoc",
"build-gh-pages": "npm run build-docs",
"commit-msg": "commitlint --edit",
"cover": "c8 --all --src src --reporter=lcov npm test",
"install-hooks": "husky install",
"lint-config": "fixpack --dryRun",
Expand All @@ -53,6 +54,8 @@
"@babel/polyfill": "7.12.1",
"@babel/preset-env": "7.13.10",
"@babel/register": "7.13.8",
"@commitlint/cli": "12.0.1",
"@js-library/commitlint-config": "0.0.3",
"ava": "3.15.0",
"c8": "7.6.0",
"coveralls": "3.1.0",
Expand Down

0 comments on commit 850eabe

Please sign in to comment.