From e869744c585faf4b4586e1bd2d9e3fa27760defb Mon Sep 17 00:00:00 2001 From: dannyl1u Date: Thu, 21 Nov 2024 18:49:01 -0800 Subject: [PATCH 1/2] fix bug --- src/issue_handler.py | 39 +++++++++++++++++++++++---------------- src/vector_db.py | 2 +- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/issue_handler.py b/src/issue_handler.py index 5d05b37..a721104 100644 --- a/src/issue_handler.py +++ b/src/issue_handler.py @@ -14,24 +14,31 @@ def handle_new_issue( full_issue = f"{issue_title} {issue_body}" similar_issue = query_similar_issue(full_issue, repo_id) - if similar_issue and similar_issue["distance"] < 1 - SIMILARITY_THRESHOLD: - comment_text = f"Closed due to high similarity with issue #{similar_issue['issue_number']} with title '{similar_issue['title']}'" - leave_comment(installation_id, repo_full_name, issue_number, comment_text) - close_issue(installation_id, repo_full_name, issue_number) - logger.info( - f"The new issue #{issue_number} with title '{issue_title}' is most similar to existing issue #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}." - ) - elif similar_issue and similar_issue["distance"] < 1 - (SIMILARITY_THRESHOLD * 0.5): - comment_text = f"Possibly related to issue #{similar_issue['issue_number']} with title '{similar_issue['title']}'" - leave_comment(installation_id, repo_full_name, issue_number, comment_text) - logger.info( - f"The new issue #{issue_number} with title '{issue_title}' is possibly similar to existing issue #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}." - ) + if similar_issue: + if similar_issue["distance"] < 1 - SIMILARITY_THRESHOLD: + comment_text = f"Closed due to high similarity with issue #{similar_issue['issue_number']} with title '{similar_issue['title']}'" + leave_comment(installation_id, repo_full_name, issue_number, comment_text) + close_issue(installation_id, repo_full_name, issue_number) + logger.info( + f"The new issue #{issue_number} with title '{issue_title}' is most similar to existing issue #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}." + ) + elif similar_issue["distance"] < 1 - (SIMILARITY_THRESHOLD * 0.5): + comment_text = f"Possibly related to issue #{similar_issue['issue_number']} with title '{similar_issue['title']}'" + leave_comment(installation_id, repo_full_name, issue_number, comment_text) + logger.info( + f"The new issue #{issue_number} with title '{issue_title}' is possibly similar to existing issue #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}." + ) + else: + comment_text = f"Most likely a new issue, most similar issue: #{similar_issue['issue_number']} with title '{similar_issue['title']}'" + leave_comment(installation_id, repo_full_name, issue_number, comment_text) + logger.info( + f"The new issue #{issue_number} with title '{issue_title}' is not similar enough to close, most similar: #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}" + ) else: - comment_text = f"Most likely a new issue, most similar issue: #{similar_issue['issue_number']} with title '{similar_issue['title']}'" + comment_text = "No similar issues found. This seems to be a new issue." leave_comment(installation_id, repo_full_name, issue_number, comment_text) logger.info( - f"The new issue #{issue_number} with title '{issue_title}' is not similar enough to close, most similar: #{similar_issue['issue_number']} with title '{similar_issue['title']}', with a cosine similarity of {1 - similar_issue['distance']:.2f}" + f"The new issue #{issue_number} with title '{issue_title}' has no similar issues in the database." ) - add_issue_to_chroma(full_issue, issue_number, issue_title, repo_id) + add_issue_to_chroma(full_issue, issue_number, issue_title, repo_id) \ No newline at end of file diff --git a/src/vector_db.py b/src/vector_db.py index b7ab0b0..e6763e9 100644 --- a/src/vector_db.py +++ b/src/vector_db.py @@ -49,7 +49,7 @@ def remove_issues_from_chroma(repo_id): collection.delete(ids=results["ids"]) -def add_issues_to_chroma(issues): +def add_issues_to_chroma(issues, repo_id): for issue in issues: issue_number = issue["number"] issue_title = issue["title"] From e447a0a16286ffaccafa96555226c2eca748b952 Mon Sep 17 00:00:00 2001 From: dannyl1u Date: Thu, 21 Nov 2024 18:50:12 -0800 Subject: [PATCH 2/2] run linter --- src/issue_handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/issue_handler.py b/src/issue_handler.py index a721104..ec9202b 100644 --- a/src/issue_handler.py +++ b/src/issue_handler.py @@ -41,4 +41,4 @@ def handle_new_issue( f"The new issue #{issue_number} with title '{issue_title}' has no similar issues in the database." ) - add_issue_to_chroma(full_issue, issue_number, issue_title, repo_id) \ No newline at end of file + add_issue_to_chroma(full_issue, issue_number, issue_title, repo_id)