Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(repo): add TODO & FIXME checker
Browse files Browse the repository at this point in the history
adamperkowski committed Nov 21, 2024
1 parent 90d50ab commit a0dafbd
Showing 3 changed files with 82 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/todos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: TODO Check
on:
push:
branches: ["main"]
paths:
- '**/*.rs'
- 'src/**/*'
pull_request:
paths:
- '**/*.rs'
- 'src/**/*'
workflow_dispatch:

jobs:
check-todos:
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4

- name: Set outputs
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "todos_old=$(cat .todos)" >> $GITHUB_OUTPUT
- run: sh check_todos.sh --count

- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: .todos for ${{ steps.vars.outputs.sha_short }}
file_pattern: '.todos'

- name: Check TODOs & FIXMEs
run: |
if [ "$(cat .todos)" -gt "$todos_old" ]; then
echo "TODO & FIXME count increased."
exit 1
fi
1 change: 1 addition & 0 deletions .todos
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
40 changes: 40 additions & 0 deletions check_todos.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#! /bin/sh
if [ ! -f '.todos' ]; then
echo "run this in nvrs' parent directory."
exit 1
fi

todo_grep=$(grep -rni 'TODO\|FIXME' ./* --exclude-dir=target --exclude=banner.webp --exclude=check_todos.sh | cut -d':' -f1,2)

if [ -z "$todo_grep" ]; then
echo 0 > .todos
exit 0
fi

echo "$todo_grep" | wc -l > .todos

if [ "$1" = '--count' ]; then
exit 0
fi

if ! command -v 'bat'; then
echo "bat not found."
exit 1
fi

for todo in $todo_grep; do
file=$(echo "$todo" | cut -d':' -f1 | cut -c 3-)
line=$(echo "$todo" | cut -d':' -f2)

if [ $(( line - 20 )) -lt 1 ]; then
line_min=1
else
line_min=$(( line - 20 ))
fi

clear
bat "$file" -r "$line_min:$(( line + 20 ))" -H "$line" -P

echo "hit ENTER to continue."
read -r _
done

0 comments on commit a0dafbd

Please sign in to comment.