fix: push_file auto-fetch sha for existing files
Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run

This commit is contained in:
Chris Christiansen 2026-06-29 14:00:05 +00:00
parent d92066aa85
commit 5ea4b0189c

View File

@ -183,9 +183,20 @@ async def push_file(p):
repo = p.get("repo", GITEA_REPO) repo = p.get("repo", GITEA_REPO)
path = p.get("path") path = p.get("path")
content = base64.b64encode(p.get("content", "").encode()).decode() content = base64.b64encode(p.get("content", "").encode()).decode()
body = {"message": p.get("message", f"chore: oppdater {path} via opax-mcp"), "content": content, "branch": p.get("branch", "main")} body = {
if p.get("sha"): "message": p.get("message", f"chore: update {path} via opax-mcp"),
"content": content,
"branch": p.get("branch", "main"),
}
if not p.get("sha"):
try:
existing = await _gitea_get(f"/repos/{repo}/contents/{path}?ref={p.get('branch','main')}")
body["sha"] = existing["sha"]
except Exception:
pass
else:
body["sha"] = p["sha"] body["sha"] = p["sha"]
if "sha" in body:
return await _gitea_put(f"/repos/{repo}/contents/{path}", body) return await _gitea_put(f"/repos/{repo}/contents/{path}", body)
return await _gitea_post(f"/repos/{repo}/contents/{path}", body) return await _gitea_post(f"/repos/{repo}/contents/{path}", body)