Update dedupe logic (#1460)

This commit is contained in:
Jeremiah Lowin 2025-08-11 18:49:52 -04:00 committed by GitHub
commit 26a2c2ed62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 12 deletions

View file

@ -169,7 +169,7 @@ class GitHubClient:
return reactions
def close_issue(self, issue_number: int, comment: str) -> bool:
"""Close an issue with a comment."""
"""Close an issue with a comment and add duplicate label."""
# First add the comment
comment_url = f"{self.base_url}/issues/{issue_number}/comments"
with httpx.Client() as client:
@ -181,6 +181,16 @@ class GitHubClient:
print(f"Failed to add comment to issue #{issue_number}")
return False
# Add the duplicate label
labels_url = f"{self.base_url}/issues/{issue_number}/labels"
with httpx.Client() as client:
response = client.post(
labels_url, headers=self.headers, json={"labels": ["duplicate"]}
)
if response.status_code not in [200, 201]:
print(f"Failed to add duplicate label to issue #{issue_number}")
# Then close the issue
issue_url = f"{self.base_url}/issues/{issue_number}"
with httpx.Client() as client:
@ -194,11 +204,10 @@ class GitHubClient:
def find_duplicate_comment(comments: list[Comment]) -> Comment | None:
"""Find a bot comment marking the issue as duplicate."""
for comment in comments:
# Check for the specific duplicate message format
body_lower = comment.body.lower()
# Check for the specific duplicate message format from a bot
if (
"possible duplicate issue" in body_lower
and "this issue will be automatically closed as a duplicate" in body_lower
comment.user_type == "Bot"
and "possible duplicate issues" in comment.body.lower()
):
return comment
return None