Skip to content

Commit f6b167b

Browse files
committed
Add Gemini API-review workflow and script
1 parent 17104da commit f6b167b

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

hack/gemini_api_review.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
import os
33
import json
44
import requests
5+
<<<<<<< HEAD
56
from google import genai
7+
=======
8+
>>>>>>> a53a08dd494 (Add Gemini API-review workflow and script)
69

710

811
def gather_markdown_files(file_paths):
@@ -37,20 +40,30 @@ def post_comment_to_pr(repository, pr_number, comment_body, github_token):
3740

3841
def main():
3942
# Define the markdown files to be gathered
43+
<<<<<<< HEAD
4044
# file_paths = ["README.md", "docs/api-guidelines.md", "docs/api-changes.md"]
4145
file_paths = ["README.md"]
46+
=======
47+
file_paths = ["README.md", "docs/api-guidelines.md", "docs/api-changes.md"]
48+
>>>>>>> a53a08dd494 (Add Gemini API-review workflow and script)
4249
docs = gather_markdown_files(file_paths)
4350

4451
# Retrieve environment variables for PR data and Gemini API credentials
4552
pr_number = os.environ.get("PR_NUMBER")
4653
pr_title = os.environ.get("PR_TITLE")
4754
pr_body = os.environ.get("PR_BODY")
55+
<<<<<<< HEAD
4856
gemini_api_key = os.environ.get("GEMINI_API_KEY") # Now used with google-genai
57+
=======
58+
gemini_api_endpoint = os.environ.get("GEMINI_API_ENDPOINT")
59+
gemini_api_key = os.environ.get("GEMINI_API_KEY")
60+
>>>>>>> a53a08dd494 (Add Gemini API-review workflow and script)
4961

5062
# Retrieve GitHub info for posting a comment
5163
github_token = os.environ.get("GITHUB_TOKEN")
5264
repository = os.environ.get("GITHUB_REPOSITORY")
5365

66+
<<<<<<< HEAD
5467
if not all([pr_number, pr_title, pr_body, gemini_api_key]):
5568
print("Error: One or more required environment variables (PR_NUMBER, PR_TITLE, PR_BODY, GEMINI_API_KEY) are missing.")
5669
return
@@ -71,12 +84,42 @@ def main():
7184
contents=contents
7285
)
7386
print(f"Gemini API response: {response.text}")
87+
=======
88+
if not all([pr_number, pr_title, pr_body, gemini_api_endpoint, gemini_api_key]):
89+
print("Error: One or more required environment variables (PR_NUMBER, PR_TITLE, PR_BODY, GEMINI_API_ENDPOINT, GEMINI_API_KEY) are missing.")
90+
return
91+
92+
# Build JSON payload for Gemini API request
93+
payload = {
94+
"pr_number": pr_number,
95+
"pr_title": pr_title,
96+
"pr_body": pr_body,
97+
"docs": docs
98+
}
99+
100+
headers = {
101+
"Authorization": f"Bearer {gemini_api_key}",
102+
"Content-Type": "application/json"
103+
}
104+
105+
try:
106+
print("Sending payload to Gemini API...")
107+
response = requests.post(gemini_api_endpoint, headers=headers, json=payload)
108+
print(f"Response status code: {response.status_code}")
109+
print(f"Response body: {response.text}")
110+
>>>>>>> a53a08dd494 (Add Gemini API-review workflow and script)
74111

75112
# If GitHub credentials are provided, post a comment with the Gemini API response
76113
if github_token and repository:
77114
comment_body = (
115+
<<<<<<< HEAD
78116
"Gemini API Review Result:\n\n"
79117
f"{response.text}"
118+
=======
119+
f"Gemini API Review Result:\n\n"
120+
f"Response Status Code: {response.status_code}\n\n"
121+
f"Response Body:\n{response.text}"
122+
>>>>>>> a53a08dd494 (Add Gemini API-review workflow and script)
80123
)
81124
post_comment_to_pr(repository, pr_number, comment_body, github_token)
82125
else:

0 commit comments

Comments
 (0)