Skip to content

Instantly share code, notes, and snippets.

@pm-coelho
Created February 2, 2020 01:07
Show Gist options
  • Save pm-coelho/4f28f9a4fba587823df9a12e84238d53 to your computer and use it in GitHub Desktop.
Save pm-coelho/4f28f9a4fba587823df9a12e84238d53 to your computer and use it in GitHub Desktop.
django pre-push hook
#!/bin/sh
NC='\033[0m'
RED='\033[1;31m'
GREEN='\033[1;32m'
ORANGE='\033[1;33m'
BLUE='\033[1;34m'
# check if graphql schema was updated
echo -n -e "${ORANGE}CHECKING${NC}: GRAPHQL Schema Update..."
docker-compose run --rm api ./manage.py graphql_schema > /dev/null 2>&1
git diff --exit-code docs/schema.json
if [ $? -ne 0 ]; then
echo -e " [ ${RED}FAILED!${NC} ]";
exit 1;
else
echo -e " [ ${GREEN}OK${NC} ]";
fi
# check if any breakpoint was left forgotten
echo -n -e "${ORANGE}CHECKING${NC}: Forgotten breakpoints..."
BP_FOUND=$(grep -R --exclude-dir={.venv,.git,docs,__pycache__} "breakpoint" .)
BP_FOUND_N=$(echo "$BP_FOUND" | sed "/^$/d" | wc -l)
if [ $BP_FOUND_N -ne 0 ]; then
echo -e " [ ${RED}FAILED!${NC} ]";
echo "---> Found $BP_FOUND_N breakpoints:"
echo "$BP_FOUND"
exit 1;
else
echo -e " [ ${GREEN}OK${NC} ]";
fi
# check if code is black formated
echo -n -e "${ORANGE}CHECKING${NC}: Black format..."
black --check . > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e " [ ${RED}FAILED!${NC} ]";
exit 1
else
echo -e " [ ${GREEN}OK${NC} ]";
fi
# run tests
echo -n -e "${ORANGE}CHECKING${NC}: Running tests..."
docker-compose run --rm api ./manage.py test > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -e " [ ${RED}FAILED!${NC} ]";
exit 1;
else
echo -e " [ ${GREEN}OK${NC} ]";
fi
# check if todos left (warning only)
echo -n -e "${ORANGE}CHECKING${NC}: Pending TODOs..."
TODOS_FOUND=$(grep -R --exclude-dir={.venv,.git,docs,__pycache__,static} "TODO:" .)
TODOS_FOUND_N=$(echo "$TODOS_FOUND" | sed "/^$/d" | wc -l)
if [ $TODOS_FOUND_N -ne 0 ]; then
echo -e " [ ${ORANGE}WARNING!${NC} ] ($TODOS_FOUND_N)";
else
echo -e " [ ${GREEN}OK${NC} ]";
fi
echo
echo -e "${RED}DON'T FORGET${NC}: Keep insomnia collection updated"
echo -e " ---> ${GREEN}DONE${NC}, pushing to remote! <---"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment