-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #60 from acabouet/PGOV-554-husky-and-githooks-AC
PGOV-554: Githook pre-commit config
- Loading branch information
Showing
9 changed files
with
675 additions
and
492 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/sh | ||
# | ||
# An example hook script to check the commit log message. | ||
# Called by "git commit" with one argument, the name of the file | ||
# that has the commit message. The hook should exit with non-zero | ||
# status after issuing an appropriate message if it wants to stop the | ||
# commit. The hook is allowed to edit the commit message file. | ||
# | ||
# To enable this hook, rename this file to "commit-msg". | ||
|
||
# Uncomment the below to add a Signed-off-by line to the message. | ||
# Doing this in a hook is a bad idea in general, but the prepare-commit-msg | ||
# hook is more suited to it. | ||
# | ||
# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') | ||
# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" | ||
|
||
# This example catches duplicate Signed-off-by lines. | ||
|
||
test "" = "$(grep '^Signed-off-by: ' "$1" | | ||
sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { | ||
echo >&2 Duplicate Signed-off-by lines. | ||
exit 1 | ||
} |
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env bash | ||
echo "Executing .git/hooks/pre-commit..." | ||
VIOLATIONS=0 | ||
|
||
# Check backend | ||
STANDARD="Drupal" | ||
BIN="./vendor/bin" | ||
|
||
echo | ||
echo "Drupal Coder pre-commit hook – commit with the --no-verify option to skip the hook" | ||
echo | ||
|
||
# Check whether PHP_CodeSniffer can be found | ||
if [ ! -f "$BIN/phpcs" ] | ||
then | ||
echo "Drupal Coder not found – is it installed? 'composer require drupal/coder'" | ||
echo | ||
exit 1 | ||
fi | ||
|
||
# Run the sniffer | ||
echo "Running Drupal Coder." | ||
echo | ||
PHPCS=("$BIN/phpcs" "--standard=$STANDARD" "--filter=gitstaged" "--encoding=utf-8" "-p" ".") | ||
"${PHPCS[@]}" | ||
VIOLATIONS=$((VIOLATIONS + $?)) | ||
|
||
# Check frontend | ||
echo "Running Frontend Lints." | ||
echo | ||
cd src/frontend || exit 1 | ||
npm run lint-staged | ||
# Add frontend violations to the total | ||
VIOLATIONS=$((VIOLATIONS + $?)) | ||
|
||
# One or more violations detected | ||
if [ $VIOLATIONS != 0 ] | ||
then | ||
echo "Please fix each violations detected." | ||
echo | ||
exit 1 | ||
fi | ||
|
||
# Syntax OK | ||
if [ $VIOLATIONS == 0 ] | ||
then | ||
echo "No violations detected" | ||
echo | ||
exit 0 | ||
fi | ||
|
||
git update-index --again | ||
|
||
|
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
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
Oops, something went wrong.