π The fast, Pythonic way to build MCP servers and clients.
Fix auto-close MRE script posting comment without closing (#3386)
Jeremiah Lowin519f9c569cae
diff --git a/scripts/auto_close_needs_mre.py b/scripts/auto_close_needs_mre.pyindex 15c525976..a9185f584 100644--- a/scripts/auto_close_needs_mre.py+++ b/scripts/auto_close_needs_mre.py@@ -215,27 +215,43 @@ class GitHubClient:return timeline- def close_issue(self, issue_number: int, comment: str) -> bool:- """Close an issue with a comment."""- # First add the comment- comment_url = f"{self.base_url}/issues/{issue_number}/comments"- with httpx.Client() as client:- response = client.post(- comment_url, headers=self.headers, json={"body": comment}- )+ def close_issue(self, issue_number: int, comment: str) -> tuple[bool, bool]:+ """Close an issue with a comment.- if response.status_code != 201:- print(f"Failed to add comment to issue #{issue_number}")- return False+ Closes first, then comments β so a failed comment never leaves+ a misleading "closing" notice on a still-open issue.- # Then close the issue+ Returns (closed, commented) so the caller can log partial failures.+ """+ # Close the issue firstissue_url = f"{self.base_url}/issues/{issue_number}"with httpx.Client() as client:response = client.patch(issue_url, headers=self.headers, json={"state": "closed"})- return response.status_code == 200+ if response.status_code != 200:+ print(+ f"Failed to close issue #{issue_number}: "+ f"{response.status_code} {response.text}"+ )+ return False, False++ # Then add the comment+ comment_url = f"{self.base_url}/issues/{issue_number}/comments"+ with httpx.Client() as client:+ response = client.post(+ comment_url, headers=self.headers, json={"body": comment}+ )++ if response.status_code != 201:+ print(+ f"Issue #{issue_number} was closed but comment failed: "+ f"{response.status_code} {response.text}"+ )+ return True, False++ return True, Truedef find_label_application_date(@@ -371,9 +387,16 @@ def main():"**If this was closed in error**, please leave a comment explaining the situation and we'll reopen it.")- if client.close_issue(issue.number, close_message):- print(f"[SUCCESS] Closed issue #{issue.number} (needs MRE)")+ closed, commented = client.close_issue(issue.number, close_message)+ if closed:closed_count += 1+ if commented:+ print(f"[SUCCESS] Closed issue #{issue.number} (needs MRE)")+ else:+ print(+ f"[WARNING] Closed issue #{issue.number} but "+ f"comment was not posted"+ )else:print(f"[ERROR] Failed to close issue #{issue.number}")