2
2
import os
3
3
import json
4
4
import requests
5
+ < << << << HEAD
5
6
from google import genai
7
+ == == == =
8
+ >> >> >> > a53a08dd494 (Add Gemini API - review workflow and script )
6
9
7
10
8
11
def gather_markdown_files (file_paths ):
@@ -37,20 +40,30 @@ def post_comment_to_pr(repository, pr_number, comment_body, github_token):
37
40
38
41
def main ():
39
42
# Define the markdown files to be gathered
43
+ < << << << HEAD
40
44
# file_paths = ["README.md", "docs/api-guidelines.md", "docs/api-changes.md"]
41
45
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 )
42
49
docs = gather_markdown_files (file_paths )
43
50
44
51
# Retrieve environment variables for PR data and Gemini API credentials
45
52
pr_number = os .environ .get ("PR_NUMBER" )
46
53
pr_title = os .environ .get ("PR_TITLE" )
47
54
pr_body = os .environ .get ("PR_BODY" )
55
+ < << << << HEAD
48
56
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 )
49
61
50
62
# Retrieve GitHub info for posting a comment
51
63
github_token = os .environ .get ("GITHUB_TOKEN" )
52
64
repository = os .environ .get ("GITHUB_REPOSITORY" )
53
65
66
+ < << << << HEAD
54
67
if not all ([pr_number , pr_title , pr_body , gemini_api_key ]):
55
68
print ("Error: One or more required environment variables (PR_NUMBER, PR_TITLE, PR_BODY, GEMINI_API_KEY) are missing." )
56
69
return
@@ -71,12 +84,42 @@ def main():
71
84
contents = contents
72
85
)
73
86
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 )
74
111
75
112
# If GitHub credentials are provided, post a comment with the Gemini API response
76
113
if github_token and repository :
77
114
comment_body = (
115
+ < << << << HEAD
78
116
"Gemini API Review Result:\n \n "
79
117
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 )
80
123
)
81
124
post_comment_to_pr (repository , pr_number , comment_body , github_token )
82
125
else :
0 commit comments