diff --git a/opax-mcp/server.py b/opax-mcp/server.py index 1cbaa98..d66a26c 100644 --- a/opax-mcp/server.py +++ b/opax-mcp/server.py @@ -180,12 +180,23 @@ async def create_issue(p): return await _gitea_post(f"/repos/{p.get('repo', GITEA_REPO)}/issues", {"title": p.get("title"), "body": p.get("body", "")}) async def push_file(p): - repo = p.get("repo", GITEA_REPO) - path = p.get("path") + repo = p.get("repo", GITEA_REPO) + path = p.get("path") 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")} - if p.get("sha"): + body = { + "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"] + if "sha" in body: return await _gitea_put(f"/repos/{repo}/contents/{path}", body) return await _gitea_post(f"/repos/{repo}/contents/{path}", body)