Resources

Download Source Code

Summary

# Terminal
chmod +x scripts/*
./scripts/install-hooks.sh

# scripts/install-hooks.sh
#!/usr/bin/env bash

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

echo "Installing git hooks..."

ln -s ../../scripts/pre-commit.sh $GIT_DIR/hooks/pre-commit
ln -s ../../scripts/pre-push.sh $GIT_DIR/hooks/pre-push

echo "Completed!"

# scripts/pre-commit.sh
#!/usr/bin/env bash

echo "Running pre-commit hook"

./scripts/run-rubocop.sh

if [ $? -ne 0 ]; then
  echo "Code must be clean before committing"
  exit 1
fi

# scripts/pre-push.sh
#!/usr/bin/env bash

echo "Running pre-push hook"

./scripts/run-brakeman.sh
# ./scripts/run-tests.sh

if [ $? -ne 0 ]; then
  echo "Brakeman and tests must pass before pushing..."
  exit 1
fi

# scripts/run-brakeman.sh
#!/usr/bin/env bash

set -e

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

echo "Running brakeman"

bundle exec brakeman -A -q -o brakeman.html

# scripts/run-rubocop.sh
#!/usr/bin/env bash

set -e

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

echo "Running Rubocop"

bundle exec rubocop

# scripts/run-tests.sh
#!/usr/bin/env bash

set -e

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

echo "Running Tests"

bin/rails test