From b0503bb3b264e37c1d039bc161eb373f5c252966 Mon Sep 17 00:00:00 2001 From: ggman12 Date: Thu, 12 Feb 2026 15:46:11 -0500 Subject: [PATCH] fix: should update schema now --- src/contributions/approve_submission.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/contributions/approve_submission.py b/src/contributions/approve_submission.py index 6f0251d..ebdd6b7 100644 --- a/src/contributions/approve_submission.py +++ b/src/contributions/approve_submission.py @@ -100,14 +100,30 @@ def create_branch(branch_name: str, sha: str) -> None: raise +def get_file_sha(path: str, branch: str) -> str | None: + """Get the SHA of an existing file, or None if it doesn't exist.""" + try: + response = github_api_request("GET", f"/contents/{path}?ref={branch}") + return response.get("sha") + except Exception: + return None + + def create_or_update_file(path: str, content: str, message: str, branch: str) -> None: """Create or update a file in the repository.""" content_b64 = base64.b64encode(content.encode()).decode() - github_api_request("PUT", f"/contents/{path}", { + payload = { "message": message, "content": content_b64, "branch": branch, - }) + } + + # If file exists, we need to include its SHA to update it + sha = get_file_sha(path, branch) + if sha: + payload["sha"] = sha + + github_api_request("PUT", f"/contents/{path}", payload) def create_pull_request(title: str, head: str, base: str, body: str) -> dict: