-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(fix post commit): fixes post commit hooks borking the developer…
… machine (#1250)
- Loading branch information
1 parent
487a2f6
commit c42b5b5
Showing
1 changed file
with
28 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" & |