Skip to content

Commit

Permalink
chore(fix post commit): fixes post commit hooks borking the developer…
Browse files Browse the repository at this point in the history
… machine (#1250)
  • Loading branch information
doublethefish committed Dec 11, 2022
1 parent 487a2f6 commit c42b5b5
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions .husky/post-commit
Original file line number Diff line number Diff line change
@@ -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 '<SHORT_SHA> <FIRST_LINE_OF_COMMIT_MSG>'
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" &

0 comments on commit c42b5b5

Please sign in to comment.