Skip to content

Commit 87813df

Browse files
VIVAAN-DHAWANVIVAAN-DHAWAN
authored andcommitted
Handle 404 on POST/PATCH gracefully
1 parent 001651a commit 87813df

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎action/post_comment.py‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,18 @@ def main() -> int:
5353
break
5454
page += 1
5555
match = next((item for item in existing if MARKER in (item.get("body") or "")), None)
56-
if match:
57-
request(f"{base}/{match['id']}", token, "PATCH", {"body": body})
58-
print(f"Updated Diffly comment {match['id']}")
59-
else:
60-
created = request(base, token, "POST", {"body": body})
61-
print(f"Created Diffly comment {created.get('id', 'unknown')}")
56+
try:
57+
if match:
58+
request(f"{base}/{match['id']}", token, "PATCH", {"body": body})
59+
print(f"Updated Diffly comment {match['id']}")
60+
else:
61+
created = request(base, token, "POST", {"body": body})
62+
print(f"Created Diffly comment {created.get('id', 'unknown')}")
63+
except SystemExit as e:
64+
if "404" in str(e) and "GitHub API" in str(e):
65+
print(f"Warning: Could not post comment due to 404 (possibly missing permissions for PR comments in this context): {e}")
66+
else:
67+
raise
6268
return 0
6369

6470

0 commit comments

Comments
 (0)