Spaces:
Sleeping
Sleeping
fix: log sync errors instead of swallowing them
Browse files
app.py
CHANGED
|
@@ -78,17 +78,41 @@ def is_allowed(args):
|
|
| 78 |
def _try_sync_repo(owner: str, repo: str):
|
| 79 |
path = repo_path(owner, repo)
|
| 80 |
if not os.path.isdir(path) or not os.path.exists(os.path.join(path, ".git")):
|
|
|
|
|
|
|
| 81 |
return
|
| 82 |
try:
|
| 83 |
branch = subprocess.run(["git", "branch", "--show-current"], cwd=path, capture_output=True, text=True).stdout.strip() or "main"
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
if status:
|
| 87 |
-
subprocess.run(["git", "add", "-A"], cwd=path, capture_output=True)
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
|
| 94 |
def spawn(command: str, owner: str = "", repo: str = ""):
|
|
|
|
| 78 |
def _try_sync_repo(owner: str, repo: str):
|
| 79 |
path = repo_path(owner, repo)
|
| 80 |
if not os.path.isdir(path) or not os.path.exists(os.path.join(path, ".git")):
|
| 81 |
+
print(f">>> _try_sync_repo skip: no repo at {path}", file=sys.stderr)
|
| 82 |
+
sys.stderr.flush()
|
| 83 |
return
|
| 84 |
try:
|
| 85 |
branch = subprocess.run(["git", "branch", "--show-current"], cwd=path, capture_output=True, text=True).stdout.strip() or "main"
|
| 86 |
+
print(f">>> _try_sync_repo pull {owner}/{repo} branch={branch}", file=sys.stderr)
|
| 87 |
+
sys.stderr.flush()
|
| 88 |
+
pull = subprocess.run(["git", "pull", "--rebase", "origin", branch], cwd=path, capture_output=True, text=True, timeout=30)
|
| 89 |
+
if pull.returncode != 0:
|
| 90 |
+
print(f">>> _try_sync_repo pull failed: rc={pull.returncode} {pull.stderr.strip()}", file=sys.stderr)
|
| 91 |
+
sys.stderr.flush()
|
| 92 |
+
status = subprocess.run(["git", "status", "--short", "--branch"], cwd=path, capture_output=True, text=True).stdout.strip()
|
| 93 |
+
print(f">>> _try_sync_repo status: {status!r}", file=sys.stderr)
|
| 94 |
+
sys.stderr.flush()
|
| 95 |
if status:
|
| 96 |
+
add = subprocess.run(["git", "add", "-A"], cwd=path, capture_output=True, text=True)
|
| 97 |
+
if add.returncode != 0:
|
| 98 |
+
print(f">>> _try_sync_repo add failed: {add.stderr.strip()}", file=sys.stderr)
|
| 99 |
+
commit = subprocess.run(["git", "commit", "-m", "codexa: auto-sync"], cwd=path, capture_output=True, text=True)
|
| 100 |
+
if commit.returncode != 0:
|
| 101 |
+
print(f">>> _try_sync_repo commit failed: rc={commit.returncode} {commit.stderr.strip()}", file=sys.stderr)
|
| 102 |
+
sys.stderr.flush()
|
| 103 |
+
else:
|
| 104 |
+
print(f">>> _try_sync_repo committed: {commit.stdout.strip()}", file=sys.stderr)
|
| 105 |
+
sys.stderr.flush()
|
| 106 |
+
push = subprocess.run(["git", "push", "origin", f"HEAD:{branch}"], cwd=path, capture_output=True, text=True, timeout=30)
|
| 107 |
+
if push.returncode != 0:
|
| 108 |
+
print(f">>> _try_sync_repo push failed: rc={push.returncode} {push.stderr.strip()}", file=sys.stderr)
|
| 109 |
+
sys.stderr.flush()
|
| 110 |
+
else:
|
| 111 |
+
print(f">>> _try_sync_repo pushed to {branch}", file=sys.stderr)
|
| 112 |
+
sys.stderr.flush()
|
| 113 |
+
except Exception as e:
|
| 114 |
+
print(f">>> _try_sync_repo exception: {e}", file=sys.stderr)
|
| 115 |
+
sys.stderr.flush()
|
| 116 |
|
| 117 |
|
| 118 |
def spawn(command: str, owner: str = "", repo: str = ""):
|