From 014a8f3411224851ff64ec117fa4ac1dd5d4eafa Mon Sep 17 00:00:00 2001 From: Fabian Kirchner Date: Tue, 10 May 2022 09:13:29 +0200 Subject: initial commit --- issues.sh | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 issues.sh (limited to 'issues.sh') 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 -- cgit v1.2.3