@@ -43,7 +43,24 @@ def download_and_combine_guidelines(bucket_name, prefix):
43
43
print (f"Error downloading or combining guidelines: { e } " )
44
44
return ""
45
45
46
- def generate_gemini_review_with_annotations (diff_file , api_key , guidelines ):
46
+ def download_and_combine_pr_comments (bucket_name , prefix ):
47
+ """Downloads text files from GCS using the google-cloud-storage library."""
48
+ try :
49
+ storage_client = storage .Client ()
50
+ bucket = storage_client .bucket (bucket_name )
51
+ blobs = bucket .list_blobs (prefix = prefix ) # Use prefix for efficiency
52
+
53
+ pr_comments_content = ""
54
+ for blob in blobs :
55
+ if blob .name .endswith (".txt" ):
56
+ pr_comments_content += blob .download_as_text () + "\n \n "
57
+ return pr_comments_content
58
+
59
+ except Exception as e :
60
+ print (f"Error downloading or combining PR comments: { e } " )
61
+ return ""
62
+
63
+ def generate_gemini_review_with_annotations (diff_file , api_key , guidelines , pr_comments ):
47
64
"""Generates a code review with annotations, incorporating guidelines."""
48
65
genai .configure (api_key = api_key )
49
66
model = genai .GenerativeModel ('gemini-2.0-flash' )
@@ -59,6 +76,10 @@ def generate_gemini_review_with_annotations(diff_file, api_key, guidelines):
59
76
60
77
{ guidelines }
61
78
79
+ The following are the previous PR comments history:
80
+
81
+ { pr_comments }
82
+
62
83
Review the following code diff from file `{ diff_file .filename } ` and provide feedback.
63
84
Point out potential issues, suggest improvements, and highlight good practices.
64
85
For each issue or suggestion, specify the line numbers from the diff where the change occurs.
@@ -129,8 +150,12 @@ def main():
129
150
print ("Failed to retrieve PR diff files from latest commit. Exiting." )
130
151
return
131
152
153
+ pr_comments = download_and_combine_pr_comments ("hackathon-sme-code-review-train" , "pr_comments/" )
154
+ if not pr_comments :
155
+ print ("Warning: No PR comments loaded. Review will proceed without PR comments history." )
156
+
132
157
for diff_file in diff_files :
133
- review_comment = generate_gemini_review_with_annotations (diff_file , api_key , guidelines )
158
+ review_comment = generate_gemini_review_with_annotations (diff_file , api_key , guidelines , pr_comments )
134
159
post_github_review_comments (repo_name , pr_number , diff_file , review_comment , github_token )
135
160
136
161
if __name__ == "__main__" :
0 commit comments