File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change 2
2
import os
3
3
from github import Github
4
4
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 ."""
7
7
g = Github (github_token )
8
8
repo = g .get_repo (repo_name )
9
9
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
12
26
13
27
def generate_gemini_review (diff , api_key ):
14
28
"""Generates a code review using the Gemini API."""
You can’t perform that action at this time.
0 commit comments