Skip to content

Instantly share code, notes, and snippets.

@fsdevblog
Last active February 21, 2021 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsdevblog/12ceacc5de9239628710b4085cc82057 to your computer and use it in GitHub Desktop.
Save fsdevblog/12ceacc5de9239628710b4085cc82057 to your computer and use it in GitHub Desktop.
Git, brakeman, rubocop, tests pre-hooks
  1. Создаем в корне апп папку scripts
  2. Сооздаем в ней несколько файлов со следующим содержимым

run-tests.bash

#!/usr/bin/env bash

set -e

cd "${0%/*}/.."

echo "Running tests"
bundle exec rspec

run-rubocop.bash

#!/usr/bin/env bash

set -e

cd "${0%/*}/.."

echo "Running rubocop"
bundle exec rubocop -A

run-brakeman.bash

#!/usr/bin/env bash

set -e

cd "${0%/*}/.."

echo "Running brakeman"
bundle exec brakeman -6

pre-push.bash

#!/usr/bin/env bash

echo "Running pre-push hook"
./scripts/run-brakeman.bash
./scripts/run-tests.bash

# $? stores exit value of the last command
if [ $? -ne 0 ]; then
 echo "Brakeman and Tests must pass before pushing!"
 exit 1
fi

pre-commit.bash

#!/usr/bin/env bash

echo "Running pre-commit hook"
./scripts/run-rubocop.bash

# $? stores exit value of the last command
if [ $? -ne 0 ]; then
 echo "Code must be clean before commiting"
 exit 1
fi

install-hooks.bash

#!/usr/bin/env bash

GIT_DIR=$(git rev-parse --git-dir)

echo "Installing hooks..."
# this command creates symlink to our pre-commit script
ln -s ../../scripts/pre-commit.bash $GIT_DIR/hooks/pre-commit
ln -s ../../scripts/pre-push.bash $GIT_DIR/hooks/pre-push
echo "Done!"
  1. Выполняем команду
$ chmod +x scripts/*.bash
$ ./scripts/install-hooks.bash
Installing hooks...
Done!

Всё. Вы прекрасны

@menonrails
Copy link

Спасибо!)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment