Skip to content

Instantly share code, notes, and snippets.

@abey79
Last active November 30, 2023 10:06
Show Gist options
  • Save abey79/0597fac8aa954007bee99e9c91e561b4 to your computer and use it in GitHub Desktop.
Save abey79/0597fac8aa954007bee99e9c91e561b4 to your computer and use it in GitHub Desktop.
Use rerun to track the number of "TODOs" in a code base across commits
from pathlib import Path
from git import Repo
import rerun as rr
GIT_REPO = Path("/tmp") / "rerun"
if not GIT_REPO.exists():
repo = Repo.clone_from("https://github.com/rerun-io/rerun.git", GIT_REPO)
else:
repo = Repo(GIT_REPO)
origin = repo.remotes.origin
origin.fetch()
origin.pull()
main_branch = repo.heads["main"]
main_branch.checkout()
all_commits = list(reversed(list(repo.iter_commits(main_branch.name))))
rr.init("rerun_example_todo_count", spawn=True)
# Iterate through the list of commits
for i, commit in enumerate(all_commits):
todo_count = 0
for blob in commit.tree.traverse():
if blob.type == 'blob': # blobs are files
todo_count += blob.data_stream.read().decode(errors='ignore').count("TODO(")
#print(f"{commit.hexsha} {commit.author.name} {commit.authored_datetime} {todo_count}")
rr.set_time_sequence("commit_idx", i)
rr.set_time_seconds("commit_time", commit.authored_datetime.timestamp())
rr.log("commit", rr.TextLog(f"{commit.hexsha} - {commit.author.name} - {commit.summary}"))
rr.log("todos", rr.TimeSeriesScalar(scalar=todo_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment