def _git_commit_tasks() -> None:
- """保存任务清单后自动提交到 git。失败仅告警,不影响接口正常返回。"""
+ """保存任务清单后自动提交到 git,并同步推送到 github。失败仅告警,不影响接口正常返回。"""
try:
with _GIT_LOCK:
subprocess.run(["git", "add", "--", _tasks_git_rel()], cwd=_REPO_ROOT,
# 无实际变更时 git commit 返回非 0,忽略
if r.returncode == 0:
logger.info("任务清单已自动 git commit")
+ # 同步推送到 github(令牌写在 remote URL 中)
+ p = subprocess.run(["git", "push", "github", "master"],
+ cwd=_REPO_ROOT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
+ if p.returncode == 0:
+ logger.info("任务清单已自动 git push 到 github")
+ else:
+ logger.warning("任务清单 git push 到 github 失败(本地 commit 已保留)")
except Exception as e:
logger.warning(f"任务清单 git commit 失败(文件已保存): {e}")