From c42b5b567db2f20871ab6acd8894526a3a14e85d Mon Sep 17 00:00:00 2001 From: Frank Harrison Date: Sun, 11 Dec 2022 18:00:28 +0000 Subject: [PATCH] chore(fix post commit): fixes post commit hooks borking the developer machine (#1250) --- .husky/post-commit | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/.husky/post-commit b/.husky/post-commit index f5d2cbcb..9ca8cefd 100755 --- a/.husky/post-commit +++ b/.husky/post-commit @@ -1,16 +1,40 @@ #!/bin/sh . "$(dirname "$0")/_/husky.sh" +SHORT_SHA=$(git rev-parse HEAD) +LINT_LOG="$TMPDIR"/ncu.lint."$SHORT_SHA".log + # display a notification -# if osascript is not supported, do nothing notify() { + # if osascript is not supported, do nothing if [ -f /usr/bin/osascript ]; then - /usr/bin/osascript -e "display notification \"$*\" with title \"Notification\"" + # get ' ' + COMMIT_INFO=$(git log --oneline -n 1 --format="%h %s") + + # read back in the lint errors + # TODO: update for each tye of error + ERRORS=$(cat "$LINT_LOG" | sed 1,4d) + + # Trigger apple- or OSA-script on supported platforms + /usr/bin/osascript -e "display notification \"$ERRORS\" with title \"ncu: $COMMIT_INFO: $*\"" fi + + # always clean up the lint output, and do not clag-up TMPDIR + rm "$LINT_LOG" } # ensure failed lint exit code passes through sed set -o pipefail -# omit first 4 lines printed by npm run -npm run lint:src 2>&1 | sed 1,4d || notify "Lint Error" & +branch=$(git branch --show-current) +# Do NOT run this when rebasing or we can't get the branch +if [ -z "$branch" ]; then + exit 0 +fi + +# Lint asynchrously, not blocking the terminal and piping all output to a file. +# IFF lint fails trigger a pop-up (on supported platforms) with at least the +# first error shown. +# We pipe output so that the terminal (tmux, vim, emacs etc.) isn't borked by +# stray output. +npm run lint:src &> "$LINT_LOG" || notify "Lint Error" &