Skip to content

Commit fa960ca

Browse files
authored
Update gemini_review.py
1 parent 7e20e2c commit fa960ca

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

hack/gemini_review.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22
import os
33
from github import Github
44

5-
def get_pr_diff(repo_name, pr_number, github_token):
6-
"""Retrieves and cleans the PR diff using PyGithub."""
5+
def get_pr_latest_commit_diff(repo_name, pr_number, github_token):
6+
"""Retrieves and cleans the diff from the latest commit of a PR."""
77
g = Github(github_token)
88
repo = g.get_repo(repo_name)
99
pr = repo.get_pull(pr_number)
10-
diff = pr.get_commits().files.patch # Get diff from the latest commit
11-
return diff
10+
11+
try:
12+
commits = list(pr.get_commits()) # Get all commits in the PR
13+
if commits:
14+
latest_commit = commits[-1] # Get the latest commit
15+
files = latest_commit.files
16+
combined_diff = ""
17+
for file in files:
18+
if file.patch:
19+
combined_diff += file.patch + "\n"
20+
return combined_diff
21+
else:
22+
return None # No commits in the PR
23+
except Exception as e:
24+
print(f"Error getting diff from latest commit: {e}")
25+
return None
1226

1327
def generate_gemini_review(diff, api_key):
1428
"""Generates a code review using the Gemini API."""

0 commit comments

Comments
 (0)