-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_repo_check.py
More file actions
73 lines (57 loc) · 2.43 KB
/
auto_repo_check.py
File metadata and controls
73 lines (57 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""PostToolUse hook: after git push to public repos → remind to check README/description sync."""
import json
import re
import subprocess
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from hook_base import run_hook
# Auto-detect: any repo under nardovibecoding is public and should have up-to-date READMEs
# No hardcoded list — checks the git remote URL instead
PUBLIC_ORG = "nardovibecoding"
def check(tool_name, tool_input, input_data):
if tool_name != "Bash":
return False
cmd = tool_input.get("command", "")
return bool(re.search(r"git\s+push", cmd))
def action(tool_name, tool_input, input_data):
cwd = input_data.get("cwd", "")
# Detect which repo we pushed to
try:
result = subprocess.run(
["git", "-C", cwd or ".", "remote", "get-url", "origin"],
capture_output=True, text=True, timeout=5
)
remote_url = result.stdout.strip()
except Exception:
return None
# Check if it's one of our public repos (any repo under nardovibecoding)
if PUBLIC_ORG not in remote_url:
return None # Not our org, skip
# Extract repo name from URL
repo_name = remote_url.rstrip("/").split("/")[-1].replace(".git", "")
# Check if README exists and has recent changes
readme = Path(cwd or ".") / "README.md"
if not readme.exists():
return f"📋 **Pushed to public repo {repo_name}** but no README.md found. Write one using `github_readme_sync` for tables."
# Check what was pushed — if any SKILL.md, hooks, or server.py changed, README might be stale
try:
result = subprocess.run(
["git", "-C", cwd or ".", "diff", "--name-only", "HEAD~1", "HEAD"],
capture_output=True, text=True, timeout=5
)
changed = result.stdout.strip().splitlines()
except Exception:
changed = []
stale_triggers = ["SKILL.md", "server.py", "hooks/", "patterns.py", "pyproject.toml"]
stale_files = [f for f in changed if any(t in f for t in stale_triggers)]
if stale_files and "README.md" not in changed:
return (
f"📋 **Pushed to {repo_name}** — these changes may affect README:\n"
f"{', '.join(stale_files[:5])}\n"
f"Call `repo_sync_check` to verify, then update README if needed."
)
return None
if __name__ == "__main__":
run_hook(check, action, "auto_repo_check")