Skip to content

Instantly share code, notes, and snippets.

@tooky
Created September 18, 2017 14:53
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tooky/f4b3ac4072a834fd5914b59a28ae86ff to your computer and use it in GitHub Desktop.
Save tooky/f4b3ac4072a834fd5914b59a28ae86ff to your computer and use it in GitHub Desktop.
Bumbailiff - A script for ageing TODO comments in code.
#!/usr/bin/env bash
#
# The bumbailiff allows the team to take up a small amount of technical debt
# (TODOs in the code) for a limited period. After that period the script fails.
#
# It will find // TODO in .js or .jsx files, and # TODO in .feature files.
#
# For example, if the allowed period for all the TODOs is 14 days.
# * It's OK to have 1 TODO that is 13 days old
# * It's OK to have 3 TODOs that are 4 days old
# * It's NOT OK to have 3 TODOs that are 5 days old
# * It's NOT OK to have 1 TODO that is 14 days old
#
# Originally written by @aslakhellesoy and extended by the Cucumber Pro team
#
if [ -n "$BUMBAILIFF_IGNORE_LA_LA_LA" ] ; then exit 0 ; fi
set -uf -o pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
ORANGE='\033[0;33m'
BLUE='\033[0;34m'
BOLD='\033[1m'
NC='\033[0m'
LIGHT_GRAY='\033[0;37m'
MAX_AGE=150
OK_AGE=$(($MAX_AGE / 2))
todos=$((git grep --files-with-matches "\(\/\/\|\#\)\s*TODO" -- "*.js" "*.jsx" "*.feature" || echo "") | xargs -I % sh -c 'echo %; git blame --date=raw % | grep "\(\/\/\|\#\)\s*TODO"')
now_seconds_since_epoch=$(date +%s)
total_days=0
while read -r line; do
if [[ "${line}" =~ ([0-9]{10}) ]]; then
commit_seconds_since_epoch=${BASH_REMATCH[1]}
days_old=$(( (${now_seconds_since_epoch} - ${commit_seconds_since_epoch}) / 86400 ))
total_days=$((${total_days} + ${days_old}))
shopt -s extglob
location="${line%// TODO*}"
location="${location%%*( )}"
todo="${line##*// }"
if ((${days_old}<=${OK_AGE}))
then
color="${GREEN}"
elif ((${days_old}<=${MAX_AGE}))
then
color="${ORANGE}"
else
color="${RED}"
fi
echo -e "${color}${days_old} days old${LIGHT_GRAY} ${location}${NC}\n${todo}\n"
else
echo -e "${BOLD}${line}${NC}"
fi
done <<< "${todos}"
status=0
if ((${total_days}<=${OK_AGE}))
then
color="${GREEN}"
elif ((${total_days}<=${MAX_AGE}))
then
color="${ORANGE}"
else
color="${RED}"
status=1
fi
echo -e "💵 ${color}${total_days} TODO-days accumulated. Max allowance is ${MAX_AGE}${NC}"
exit ${status}
@mattwynne
Copy link

Now released as a package: https://github.com/SmartBear/bumbailiff

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