From 78704d88aeb490f7d344188a81c074f19f49e230 Mon Sep 17 00:00:00 2001 From: siquanlv Date: Wed, 25 Jun 2025 15:05:39 +0800 Subject: [PATCH 1/2] ai review test --- src/test/java/net/lvsq/jgossip/BuggyCalculator.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/net/lvsq/jgossip/BuggyCalculator.java b/src/test/java/net/lvsq/jgossip/BuggyCalculator.java index acb8b30..05a184d 100644 --- a/src/test/java/net/lvsq/jgossip/BuggyCalculator.java +++ b/src/test/java/net/lvsq/jgossip/BuggyCalculator.java @@ -9,7 +9,6 @@ import java.util.logging.Logger; public class BuggyCalculator { - private static final Logger logger = Logger.getLogger(BuggyCalculator.class.getName()); public double divide(int numerator, int denominator) { From 8053bed5e6f2e6a721be3d7700d8ba528e9f2926 Mon Sep 17 00:00:00 2001 From: siquanlv Date: Mon, 30 Jun 2025 09:20:31 +0800 Subject: [PATCH 2/2] ai review test --- .github/scripts/ai_code_review.py | 4 +++- .github/workflows/ai_code_review.yml | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/scripts/ai_code_review.py b/.github/scripts/ai_code_review.py index e626d82..4a5bee1 100644 --- a/.github/scripts/ai_code_review.py +++ b/.github/scripts/ai_code_review.py @@ -30,9 +30,11 @@ def call_gpt(diff_text): if not api_key: raise ValueError("❌ OPENAI_API_KEY is not set.") + api_endpoint = os.environ.get("OPENAI_API_ENDPOINT") + 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", + base_url=api_endpoint, default_headers={"api-key": api_key}, ) diff --git a/.github/workflows/ai_code_review.yml b/.github/workflows/ai_code_review.yml index 9bdc98d..c27cc9e 100644 --- a/.github/workflows/ai_code_review.yml +++ b/.github/workflows/ai_code_review.yml @@ -27,20 +27,31 @@ jobs: - name: 📦 Install dependencies run: pip install openai requests + - name: ✅ Checkout the default branch + uses: actions/checkout@v4 + with: + # 在 pull_request_target 事件中,我们必须手动检出 PR 提交的代码 + # 否则它会检出主分支的代码,导致审查的是主分支而非PR分支 + ref: ${{ github.event.pull_request.h ead.sha }} + - name: 🧾 Download PR diff via GitHub API + id: pr_diff env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }} run: | - curl -s -H "Authorization: token $GITHUB_TOKEN" \ - -H "Accept: application/vnd.github.v3.diff" \ - https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER \ - -o pr.diff + # 确保 GITHUB_TOKEN 有权限读取 PR + PR_DIFF=$(gh pr view ${{ github.event.number }} --json files --jq '.files | map(.patch) | join("\n")') + # 将 diff 输出设置为一个环境变量 + echo "PR_DIFF<> $GITHUB_ENV + echo "$PR_DIFF" >> $GITHUB_ENV + echo "EOF" >> $GITHUB_ENV - name: 🤖 Run AI code review env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENAI_API_ENDPOINT: ${{ secrets.OPENAI_API_ENDPOINT }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_REPOSITORY: ${{ github.repository }} PR_NUMBER: ${{ github.event.pull_request.number }}