Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pre-commit hook checking spotless #1881

Merged
merged 10 commits into from
Aug 26, 2024
42 changes: 42 additions & 0 deletions gitHooks/hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved

echo "Running pre commit checks"

hasJavaFiles=0
hasJsFiles=0

files=`git diff --name-only --cached`
while read name
do
if [[ $name == report-viewer* ]]
then
hasJsFiles=1
fi

if [[ $name == *.java ]]
then
hasJavaFiles=1
fi
done <<< "$files"

if [[ $hasJsFiles -gt 0 ]]
then
echo "Running report viewer pre commit checks"
cd report-viewer
../gitHooks/scripts/reportViewerPreCommit
if [ $? -gt 0 ]
then
exit 1
fi
cd ..
fi

if [[ $hasJavaFiles -gt 0 ]]
then
echo "Running java pre commit checks"
gitHooks/scripts/javaPreCommit
if [ $? -gt 0 ]
then
exit 1
fi
fi
5 changes: 5 additions & 0 deletions gitHooks/installHooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/python

import subprocess
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved

subprocess.run(["git", "config", "--local", "core.hooksPath", "gitHooks/hooks"])
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions gitHooks/scripts/javaPreCommit
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

#prevents the shell from aborting if maven returns a non zero exit code
set +e
echo Checking spotless
mvn spotless:check &> /dev/null
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
exitCode=$?

if [ $exitCode -gt 0 ]
then
echo "Spotless failed. Please run 'mvn spotless:apply' to fix."
fi
exit $exitCode
3 changes: 3 additions & 0 deletions gitHooks/scripts/reportViewerPreCommit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

npx lint-staged
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 0 additions & 2 deletions report-viewer/.husky/pre-commit

This file was deleted.

24 changes: 1 addition & 23 deletions report-viewer/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions report-viewer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --max-warnings 0",
"format": "prettier --write src/",
"prepare": "cd .. && husky report-viewer/.husky"
"prepare": "cd .. && python gitHooks/installHooks.py"
},
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.6.0",
Expand Down Expand Up @@ -49,7 +49,6 @@
"autoprefixer": "^10.4.19",
"eslint": "^8.57.0",
"eslint-plugin-vue": "^9.27.0",
"husky": "^9.0.11",
"jsdom": "^24.1.0",
"lint-staged": "^15.2.7",
"npm-run-all": "^4.1.5",
Expand Down