Add Git health collector

This commit is contained in:
2026-08-03 15:55:53 -04:00
parent 4fbc2eadbe
commit df6ae1cbc9
3 changed files with 60 additions and 2 deletions
+53
View File
@@ -0,0 +1,53 @@
#!/usr/bin/env python3
import subprocess
REPOSITORIES = {
"infrastructure": "/opt/git/infrastructure",
"voyager": "/opt/git/voyager",
}
def collect():
repos = []
dirty = False
for name, path in REPOSITORIES.items():
result = subprocess.run(
["git", "-C", path, "status", "--short", "--branch"],
capture_output=True,
text=True,
)
if result.returncode != 0:
repos.append({
"name": name,
"state": "offline",
})
dirty = True
continue
lines = result.stdout.splitlines()
branch = lines[0].replace("## ", "")
modified = sum(1 for l in lines[1:] if not l.startswith("??"))
untracked = sum(1 for l in lines[1:] if l.startswith("??"))
state = "clean" if modified == 0 and untracked == 0 else "dirty"
if state != "clean":
dirty = True
repos.append({
"name": name,
"state": state,
"branch": branch,
"modified": modified,
"untracked": untracked,
})
return {
"state": "warning" if dirty else "online",
"summary": f"{len(repos)} repositories",
"detail": "All clean" if not dirty else "Repositories require attention",
"repositories": repos,
}