Created
October 26, 2018 16:12
-
-
Save gabriel-tincu/e10759604b889b9a36eeedba88a41b59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
cd $(dirname $0) | |
root_path=$(dirname $(dirname $(pwd -P))) | |
main_re="#[[:space:]]+TODO[[:space:]]+\[[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}\]" | |
date_re="[[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}" | |
today=$(date +%s) | |
search_path=$root_path | |
OIFS=$IFS | |
found_expired= | |
get_format() { | |
date_str=$1 | |
if [[ $(uname | grep -i linux) ]] | |
then | |
echo "-d $date_str" | |
else | |
vars=($(echo $date_str | sed -e "s/-/ /g")) | |
echo "-v${vars[0]}y -v${vars[1]}m -v${vars[2]}d" | |
fi | |
} | |
echo "Checking all files for due todos in $search_path" | |
for file in $(find $search_path -iname *.py 2>/dev/null) | |
do | |
export IFS=$'\n' | |
found_for_file= | |
for line in $(grep -Ei "$main_re" $file 2>/dev/null) | |
do | |
expired_lines=() | |
exp_str=$(echo $line | grep -Eio "$date_re") | |
expiry=$(date $(get_format $exp_str) +%s) | |
if [[ $today -ge $expiry ]] | |
then | |
if [[ -z $found_for_file ]] | |
then | |
found_for_file=true | |
echo "------------------------------------" | |
echo "$file" | |
fi | |
echo $line | |
found_expired=true | |
fi | |
done | |
if [[ ! -z $found_for_file ]] | |
then | |
echo | |
fi | |
export IFS=$OIFS | |
done | |
if [[ ! -z $found_expired ]] | |
then | |
echo "Found expired todo comments, exit code 1" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment