#!/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, }