From f0f9d44fdee2c11a51f1d26531369ed75b8ba3f6 Mon Sep 17 00:00:00 2001 From: Molecule AI Core-DevOps Date: Mon, 11 May 2026 19:08:38 +0000 Subject: [PATCH] fix(ci): catch urllib.error.HTTPError in gate-check-v3 comment posting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit HttpError (e.g. 403 from missing write:repository) was not caught, causing the entire script to crash after the verdict was already computed. Now wrapped in try/except — comment-posting failure is non-fatal and logged as a warning; the result with verdict is still returned. Fixes: #543 Co-Authored-By: Claude Opus 4.7 --- tools/gate-check-v3/gate_check.py | 34 +++++++++++++++++-------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/tools/gate-check-v3/gate_check.py b/tools/gate-check-v3/gate_check.py index 429c2b40..0d8fa24f 100644 --- a/tools/gate-check-v3/gate_check.py +++ b/tools/gate-check-v3/gate_check.py @@ -498,21 +498,25 @@ def run(repo: str, pr_number: int, post_comment: bool = False) -> dict: "Content-Type": "application/json", "Accept": "application/json", } - # Check if a gate-check comment already exists to avoid spamming - existing = api_list(f"/repos/{owner}/{name}/issues/{pr_number}/comments") - our_comments = [c for c in existing if "[gate-check-v3]" in (c.get("body") or "")] - if our_comments: - # Update latest - comment_id = our_comments[-1]["id"] - url = f"{API_BASE}/repos/{owner}/{name}/issues/comments/{comment_id}" - req = urllib.request.Request(url, data=json.dumps({"body": comment_body}).encode(), headers=headers, method="PATCH") - with urllib.request.urlopen(req) as r: - r.read() - else: - url = f"{API_BASE}/repos/{owner}/{name}/issues/{pr_number}/comments" - req = urllib.request.Request(url, data=json.dumps({"body": comment_body}).encode(), headers=headers, method="POST") - with urllib.request.urlopen(req) as r: - r.read() + try: + # Check if a gate-check comment already exists to avoid spamming + existing = api_list(f"/repos/{owner}/{name}/issues/{pr_number}/comments") + our_comments = [c for c in existing if "[gate-check-v3]" in (c.get("body") or "")] + if our_comments: + # Update latest + comment_id = our_comments[-1]["id"] + url = f"{API_BASE}/repos/{owner}/{name}/issues/comments/{comment_id}" + req = urllib.request.Request(url, data=json.dumps({"body": comment_body}).encode(), headers=headers, method="PATCH") + with urllib.request.urlopen(req) as r: + r.read() + else: + url = f"{API_BASE}/repos/{owner}/{name}/issues/{pr_number}/comments" + req = urllib.request.Request(url, data=json.dumps({"body": comment_body}).encode(), headers=headers, method="POST") + with urllib.request.urlopen(req) as r: + r.read() + except urllib.error.HTTPError as e: + # Non-fatal: token may lack write:repository. Verdict is already computed. + print(f"Warning: could not post comment (HTTP {e.code}) — token may lack write:repository permission", file=sys.stderr) return result -- 2.52.0