fix: push_file auto-fetch sha for existing files
Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run
Some checks are pending
Check Python Version Consistency / Check Python Version (push) Waiting to run
This commit is contained in:
parent
d92066aa85
commit
5ea4b0189c
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user