git fail info
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user