diff --git a/.git-hooks/install.bash b/.git-hooks/install.bash new file mode 100755 index 0000000..756cc5c --- /dev/null +++ b/.git-hooks/install.bash @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +ln .git-hooks/pre-commit .git/hooks/pre-commit +chmod +x .git/hooks/pre-commit diff --git a/.git-hooks/pre-commit b/.git-hooks/pre-commit new file mode 100755 index 0000000..fa6f31f --- /dev/null +++ b/.git-hooks/pre-commit @@ -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" diff --git a/README.md b/README.md index f155e11..f6600b5 100644 --- a/README.md +++ b/README.md @@ -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`. + +