Skip to content

Commit 85d1571

Browse files
authored
Update ai_code_review.yml
1 parent be43f2d commit 85d1571

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

.github/workflows/ai_code_review.yml

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,55 @@ name: AI Powered Code Review
33

44
on:
55
pull_request:
6-
types: [opened, reopened, synchronize] # 当 PR 打开、重开或有新提交时触发
6+
types: [opened, reopened, synchronize]
77

88
jobs:
99
ai_review:
10-
runs-on: ubuntu-latest # 使用 Ubuntu 运行器
10+
runs-on: ubuntu-latest
1111
permissions:
12-
contents: read # 读取代码的权限
13-
pull-requests: write # 在 PR 上发表评论的权限
12+
contents: read
13+
pull-requests: write
1414

1515
steps:
1616
- name: Checkout Code
1717
uses: actions/checkout@v4
1818
with:
19-
fetch-depth: 0 # 必须获取完整的历史,以便 git diff 正确工作
19+
fetch-depth: 0
2020

2121
- name: Set up Python
2222
uses: actions/setup-python@v5
2323
with:
24-
python-version: '3.9' # 或者你喜欢的 Python 版本
24+
python-version: '3.9'
2525

2626
- name: Install Python Dependencies
27-
run: pip install openai # 或者 google-generativeai,取决于你选择的 LLM
27+
run: pip install openai
2828

29-
- name: Get Pull Request Details
29+
- name: Get Pull Request Details and Set Env # 保持这一步,它将 SHA 设置为环境变量
3030
id: pr_details
3131
run: |
3232
echo "GITHUB_BASE_REF=${{ github.event.pull_request.base.sha }}" >> $GITHUB_ENV
3333
echo "GITHUB_HEAD_REF=${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
3434
echo "GITHUB_PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
3535
echo "GITHUB_REPOSITORY=${{ github.repository }}" >> $GITHUB_ENV
3636
37+
- name: **Debug Env Vars Before Python Script** # <-- 新增的调试步骤
38+
run: |
39+
echo "Current GITHUB_BASE_REF: $GITHUB_BASE_REF"
40+
echo "Current GITHUB_HEAD_REF: $GITHUB_HEAD_REF"
41+
echo "Current GITHUB_PR_NUMBER: $GITHUB_PR_NUMBER"
42+
echo "Current GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
43+
echo "LLM_API_KEY is present: ${LLM_API_KEY:+true}" # 检查API key是否存在,不打印值
44+
env:
45+
LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }} # 需要在这里也传递,以便在此步骤中访问
46+
3747
- name: Run AI Code Review
3848
run: python .github/scripts/ai_code_reviewer.py
3949
env:
40-
LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }} # 或者 ${{ secrets.GEMINI_API_KEY }}
41-
LLM_MODEL_NAME: gpt-4o # 或者 gemini-pro
42-
# GITHUB_TOKEN 是 Actions 默认提供的,用于 API 交互,这里会被 gh cli 自动使用
43-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
50+
LLM_API_KEY: ${{ secrets.OPENAI_API_KEY }}
51+
LLM_MODEL_NAME: gpt-4o
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
# 明确传递这些环境变量,确保Python脚本能获取到正确的值
54+
GITHUB_BASE_REF: ${{ env.GITHUB_BASE_REF }}
55+
GITHUB_HEAD_REF: ${{ env.GITHUB_HEAD_REF }}
56+
GITHUB_PR_NUMBER: ${{ env.GITHUB_PR_NUMBER }}
57+
GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }}

0 commit comments

Comments
 (0)