From 35d857f65365db513f490bbd89c98899f64a8f59 Mon Sep 17 00:00:00 2001 From: JiriUhlir <149317995+JiriUhlir@users.noreply.github.com> Date: Mon, 15 Jun 2026 12:08:11 +0200 Subject: [PATCH] git fail info --- app/routes/scheduled_scripts.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/app/routes/scheduled_scripts.py b/app/routes/scheduled_scripts.py index 863746f..3862e8d 100644 --- a/app/routes/scheduled_scripts.py +++ b/app/routes/scheduled_scripts.py @@ -183,12 +183,21 @@ def _gitea_push_remote() -> tuple[str, str | None]: return f"{scheme}://{token}@{rest}/{org}/{TOOLS_REPO_NAME}.git", token +def _git_error_detail(result, token: str | None = None) -> str: + """Zkombinuje git stderr/stdout do čitelného důvodu chyby (s maskováním tokenu).""" + detail = (result.stderr or "").strip() or (result.stdout or "").strip() + if token and detail: + detail = detail.replace(token, "***") + return html.escape(detail) if detail else "git nevrátil žádný výstup" + + def commit_and_push(script_name: str, message: str, user: dict) -> None: """Zacommituje a pushne změnu jednoho maintenance skriptu do gitea (appfactory-tools).""" rel_path = f"maintenance/{script_name}" - if _git(["add", "--", rel_path]).returncode != 0: - raise HTTPException(status_code=500, detail="Git: soubor se nepodařilo přidat do indexu") + add = _git(["add", "--", rel_path]) + if add.returncode != 0: + raise HTTPException(status_code=500, detail=f"Git add selhal (v {TOOLS_REPO_DIR}): {_git_error_detail(add)}") # Žádná změna oproti HEAD -> přeskočíme, ať nevznikají prázdné commity. if _git(["diff", "--cached", "--quiet", "--", rel_path]).returncode == 0: @@ -200,16 +209,13 @@ def commit_and_push(script_name: str, message: str, user: dict) -> None: "commit", "-m", f"{message} (portál: {_git_actor(user)})", ]) if commit.returncode != 0: - raise HTTPException(status_code=500, detail="Git commit selhal") + raise HTTPException(status_code=500, detail=f"Git commit selhal (v {TOOLS_REPO_DIR}): {_git_error_detail(commit)}") branch = (_git(["rev-parse", "--abbrev-ref", "HEAD"]).stdout or "").strip() or "main" remote, token = _gitea_push_remote() push = _git(["push", remote, f"HEAD:{branch}"]) if push.returncode != 0: - detail = (push.stderr or "").strip() - if token: - detail = detail.replace(token, "***") - raise HTTPException(status_code=500, detail=f"Git push selhal: {html.escape(detail)}") + raise HTTPException(status_code=500, detail=f"Git push selhal: {_git_error_detail(push, token)}") def validate_schedule_type(value: str) -> str: