Add git hooks

This commit is contained in:
Trevor Vallender 2024-05-26 09:11:31 +01:00
parent e3f53839d5
commit c22a5ffac2
3 changed files with 44 additions and 0 deletions

4
.git-hooks/install.bash Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/env bash
ln .git-hooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

24
.git-hooks/pre-commit Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
GREEN='\033[0;32m'
AMBER='\033[0;33m'
RED='\033[0;31m'
CLEAR_COLOR='\033[0m'
function run_command {
local COMMAND=$1
local COMMAND_NAME=$2
echo -e "${AMBER}Running $COMMAND_NAME…${AMBER}"
$COMMAND &>/dev/null
if [[ $? -ne 0 ]] ; then
echo -e "${RED}❌ $COMMAND_NAME failed${CLEAR_COLOR}"
exit 1
else
echo -e "${GREEN}✓ $COMMAND_NAME passed${CLEAR_COLOR}"
fi
}
run_command "brakeman --format html -o ../tmp/brakeman.html" "Brakeman"
run_command "bundle exec rubocop" "Rubocop"
run_command "bundle exec rails test" "test suite"

View File

@ -8,3 +8,19 @@ the video chat software of your choice or offline at a physical table.
Spin up the application with `./bin/setup`.
Run tests with `rails test`.
### Git hooks
There is a pre-commit git hook stored in .git-hooks which can be installed by running `.git-hooks/install.bash`.
The hooks:
- Run Rubocop
- Run tests
- Run Brakeman
### Brakeman
If Brakeman issues are introduced, they should be immediately fixed or ignored with a note as to why it
is not a real issue. To do so, run `bundle exec brakeman -I`.