SHARE
TWEET

Untitled

a guest Oct 13th, 2017 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env bash
  2. #
  3. # The bumbailiff allows the team to take up a small amount of technical debt
  4. # (TODOs in the code) for a limited period. After that period the script fails.
  5. #
  6. # It will find // TODO in .cs files
  7. #
  8. # For example, if the allowed period for all the TODOs is 14 days.
  9. #   * It's OK to have 1 TODO that is 13 days old
  10. #   * It's OK to have 3 TODOs that are 4 days old
  11. #   * It's NOT OK to have 3 TODOs that are 5 days old
  12. #   * It's NOT OK to have 1 TODO that is 14 days old
  13. #
  14. # Originally written by @aslakhellesoy and extended by the Cucumber Pro team
  15. #
  16. if [ -n "$BUMBAILIFF_IGNORE_LA_LA_LA" ] ; then exit 0 ; fi
  17. set -uf -o pipefail
  18.  
  19.  
  20. RED='\033[0;31m'
  21. GREEN='\033[0;32m'
  22. ORANGE='\033[0;33m'
  23. BLUE='\033[0;34m'
  24. BOLD='\033[1m'
  25. NC='\033[0m'
  26. LIGHT_GRAY='\033[0;37m'
  27.  
  28. MAX_AGE=150
  29. OK_AGE=$(($MAX_AGE / 2))
  30.  
  31. todos=$((git grep --files-with-matches "\(\/\/\)\s*TODO" -- "*.cs" || echo "") | xargs -I % sh -c 'echo %; git blame --date=raw % | grep "\(\/\/\|\#\)\s*TODO"')
  32.  
  33. now_seconds_since_epoch=$(date +%s)
  34. total_days=0
  35.  
  36. while read -r line; do
  37.   if [[ "${line}" =~ ([0-9]{10}) ]]; then
  38.     commit_seconds_since_epoch=${BASH_REMATCH[1]}
  39.     days_old=$(( (${now_seconds_since_epoch} - ${commit_seconds_since_epoch}) / 86400 ))
  40.     total_days=$((${total_days} + ${days_old}))
  41.     shopt -s extglob
  42.     location="${line%// TODO*}"
  43.     location="${location%%*( )}"
  44.     todo="${line##*// }"
  45.  
  46.     if ((${days_old}<=${OK_AGE}))
  47.     then
  48.       color="${GREEN}"
  49.     elif ((${days_old}<=${MAX_AGE}))
  50.     then
  51.       color="${ORANGE}"
  52.     else
  53.       color="${RED}"
  54.     fi
  55.     echo -e "${color}${days_old} days old${LIGHT_GRAY} ${location}${NC}\n${todo}\n"
  56.   else
  57.     echo -e "${BOLD}${line}${NC}"
  58.   fi
  59. done <<< "${todos}"
  60.  
  61. status=0
  62. if ((${total_days}<=${OK_AGE}))
  63. then
  64.   color="${GREEN}"
  65. elif ((${total_days}<=${MAX_AGE}))
  66. then
  67.   color="${ORANGE}"
  68. else
  69.   color="${RED}"
  70.   status=1
  71. fi
  72.  
  73. echo -e "💵  ${color}${total_days} TODO-days accumulated. Max allowance is ${MAX_AGE}${NC}"
  74. exit ${status}
RAW Paste Data
Top