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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ try {
We're happy to incorporate all improvements to JPlag into this codebase. Feel free to fork the project and send pull requests.
Please consider our [guidelines for contributions](https://github.com/jplag/JPlag/wiki/3.-Contributing-to-JPlag).

### Git hooks
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved

The repository contains a pre-commit hook, that prevents commits if fail spotless.
To set up the hooks, call any of the installHooks scrips in gitHooks (gitHooks/installHooks (shell), gitHooks/installHooks.bat (windows), gitHooks/installHooks.py (python))

## Contact
If you encounter bugs or other issues, please report them [here](https://github.com/jplag/jplag/issues).
For other purposes, you can contact us at [email protected] .
Expand Down
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
1 change: 1 addition & 0 deletions gitHooks/installHooks.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git config --local core.hooksPath gitHooks/hooks
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
3 changes: 3 additions & 0 deletions gitHooks/installHooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

git config --local core.hooksPath gitHooks/hooks
19 changes: 19 additions & 0 deletions gitHooks/scripts/javaPreCommit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

if ! command -v <the_command> &> /dev/null #checks if maven is installed
then
echo "Maven is not installed. Spotless will not be checked"
exit 0
TwoOfTwelve marked this conversation as resolved.
Show resolved Hide resolved
fi

#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.

9 changes: 1 addition & 8 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": "git config --local core.hooksPath gitHooks/hooks"
},
"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.1.4",
"jsdom": "^24.1.1",
"lint-staged": "^15.2.7",
"npm-run-all": "^4.1.5",
Expand Down