aboutsummaryrefslogtreecommitdiffstats
path: root/issues.sh
diff options
context:
space:
mode:
authorLibravatar Fabian Kirchner <kirchner@posteo.de>2022-05-10 09:13:29 +0200
committerLibravatar Fabian Kirchner <kirchner@posteo.de>2022-05-10 09:13:29 +0200
commit014a8f3411224851ff64ec117fa4ac1dd5d4eafa (patch)
tree2005b5e93423676b7b3b03e9dcd37d8f722f262b /issues.sh
initial commit
Diffstat (limited to 'issues.sh')
-rwxr-xr-xissues.sh65
1 files changed, 65 insertions, 0 deletions
diff --git a/issues.sh b/issues.sh
new file mode 100755
index 0000000..0c3f761
--- /dev/null
+++ b/issues.sh
@@ -0,0 +1,65 @@
+#!/usr/bin/env bash
+
+set -efu
+
+tree-grepper \
+ -q elm '([(line_comment) (block_comment)]+)' \
+ --format json frontend/src/ | \
+ jq 'sort_by(.file)' | \
+ jq '.[]' --indent 0 | \
+ while read -r line; do
+ file=$(echo "$line" | jq -r .file)
+ file_type=$(echo "$line" | jq -r .file_type)
+ items=$(echo "$line" | \
+ jq '.matches[] | { file: $file, file_type: $file_type, match: . }' --arg file "$file" --arg file_type "$file_type" | \
+ jq '. | select(.match.text | test("TODO .+"))'
+ )
+ if test -z "$items"; then
+ continue
+ fi
+
+ echo "$items" | jq --slurp '.[]' --indent 0 | \
+ while read -r item; do
+ start_row=$(echo "$item" | jq '.match.start.row')
+ end_row=$(echo "$item" | jq '.match.end.row')
+
+ last_commit=$(git --no-pager blame -L "$start_row,$start_row" "$file" -p | \
+ head -n 1 | \
+ cut -d ' ' -f 1
+ )
+
+ text=$(echo "$item" | \
+ jq .match.text -r | \
+ sed 's/^-- //' | \
+ sed 's/^{- //' | \
+ sed 's/ -}$//')
+
+ first_commit=$(git --no-pager log --reverse -S"$text" --format=%H | \
+ head -n 1)
+
+ created_at=$(git show $first_commit --no-patch --format=%ad)
+ heading=$(echo "$text" | sed '/^$/Q' | sed 's/.*TODO //')
+ body=$(echo "$text" | tail -n +$(($(echo "$heading" | wc -l) + 2)) | \
+ awk -F '[^ ]' '
+ NR == 1 {n = length($1)}
+ {sub("^ {1,"n"}", ""); print}'
+ )
+
+ GREEN='\033[0;32m'
+ BOLD=$(tput bold)
+ NORMAL=$(tput sgr0)
+ NC='\033[0m'
+ echo -e "$GREEN--- $created_at --- $file$NC"
+ echo
+ echo "$BOLD$heading$NORMAL" | fold -s
+ if test -n "$body"; then
+ echo
+ echo "$body" | fold -s
+ echo
+ fi
+ echo
+ cat "$file" | nl -w 4 -s "| " -p -d '' -b a| tail -n +$(($start_row - 2)) | head -n $(($end_row - $start_row + 7))
+ echo
+ echo
+ done
+ done