Skip to content

Commit 460ebb4

Browse files
authored
Merge pull request #18 from Siquan-lab/master
ai review
2 parents e2636c6 + a59d442 commit 460ebb4

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

.github/scripts/ai_code_review.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@
22
import requests
33
import openai
44

5-
def load_diff(file_path='pr.diff'):
5+
6+
def load_diff(file_path="pr.diff"):
67
"""Load the diff content from file."""
78
if not os.path.exists(file_path):
89
print("❌ Diff file not found.")
910
return ""
10-
with open(file_path, 'r', encoding='utf-8') as f:
11+
with open(file_path, "r", encoding="utf-8") as f:
1112
return f.read()
1213

14+
1315
def call_gpt(diff_text):
1416
"""Call AI to review the diff."""
15-
api_key = os.getenv("OPENAI_API_KEY")
17+
api_key = os.environ.get("OPENAI_API_KEY")
1618
if not api_key:
1719
raise ValueError("❌ OPENAI_API_KEY is not set.")
1820

19-
client = openai.OpenAI(api_key=api_key, base_url='https://llm-proxy.us-east-2.int.infra.intelligence.webex.com/azure/v1?api-version=2024-10-21',default_headers={"api-key": api_key})
21+
client = openai.OpenAI(
22+
api_key=api_key,
23+
base_url="https://llm-proxy.us-east-2.int.infra.intelligence.webex.com/azure/v1?api-version=2024-10-21",
24+
default_headers={"api-key": api_key},
25+
)
2026

2127
prompt = f"""
2228
You are a senior Java code reviewer.
@@ -52,12 +58,13 @@ def call_gpt(diff_text):
5258
model="gpt-4o",
5359
messages=[
5460
{"role": "system", "content": "You are a Java code review expert."},
55-
{"role": "user", "content": prompt}
61+
{"role": "user", "content": prompt},
5662
],
57-
temperature=0.2
63+
temperature=0.2,
5864
)
5965
return response.choices[0].message.content
6066

67+
6168
def post_pr_comment(review_text):
6269
"""Post review result as a comment on the PR."""
6370
repo = os.getenv("GITHUB_REPOSITORY")
@@ -67,7 +74,7 @@ def post_pr_comment(review_text):
6774
url = f"https://api.github.com/repos/{repo}/issues/{pr_number}/comments"
6875
headers = {
6976
"Authorization": f"token {token}",
70-
"Accept": "application/vnd.github.v3+json"
77+
"Accept": "application/vnd.github.v3+json",
7178
}
7279
payload = {"body": review_text}
7380

@@ -79,6 +86,7 @@ def post_pr_comment(review_text):
7986
else:
8087
print("✅ Review comment posted successfully.")
8188

89+
8290
def main():
8391
diff = load_diff()
8492
if not diff.strip():
@@ -87,6 +95,6 @@ def main():
8795
review = call_gpt(diff)
8896
post_pr_comment(review)
8997

98+
9099
if __name__ == "__main__":
91100
main()
92-

src/test/java/net/lvsq/jgossip/BuggyCalculator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import java.util.logging.Logger;
1010

1111
public class BuggyCalculator {
12+
1213
private static final Logger logger = Logger.getLogger(BuggyCalculator.class.getName());
1314

15+
1416
public double divide(int numerator, int denominator) {
1517
// 潜在 Bug 1: 除以零未处理
1618
// 潜在 Bug 2: 返回 double,但参数是 int,可能导致精度问题(如果结果需要精确)

0 commit comments

Comments
 (0)