Skip to content

Commit 69718eb

Browse files
authored
Update gemini_review.py
1 parent 9606b67 commit 69718eb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

hack/gemini_review.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ def post_github_review_comments(repo_name, pr_number, diff_file, review_comment,
5656
pr = repo.get_pull(pr_number)
5757

5858
if review_comment:
59+
commits = list(pr.get_commits())
60+
if not commits:
61+
print(f"WARNING: No commits found for PR {pr_number}. Posting general issue comment for {diff_file.filename}.")
62+
pr.create_issue_comment(f"Review for {diff_file.filename}:\n{review_comment}")
63+
return # Exit the function
64+
65+
latest_commit = commits[-1]
66+
5967
# Parse the review comment for line number annotations
6068
lines_to_comment = []
6169
for line in review_comment.split('\n'):
@@ -68,7 +76,10 @@ def post_github_review_comments(repo_name, pr_number, diff_file, review_comment,
6876

6977
if lines_to_comment:
7078
for line_num in lines_to_comment:
71-
pr.create_review_comment(body=review_comment, commit=pr.get_commits()[-1], path=diff_file.filename, position=line_num)
79+
try:
80+
pr.create_review_comment(body=review_comment, commit=latest_commit, path=diff_file.filename, position=line_num)
81+
except Exception as e:
82+
print(f"ERROR: Failed to create review comment for line {line_num} in {diff_file.filename}: {e}")
7283
print(f"Review comments for {diff_file.filename} posted successfully.")
7384
else:
7485
pr.create_issue_comment(f"Review for {diff_file.filename}:\n{review_comment}")

0 commit comments

Comments
 (0)