Skip to content

test

test #36

name: AI Code Review on PR
on:
pull_request_target:
types: [opened, synchronize, reopened]
permissions:
contents: read
pull-requests: write
jobs:
AI-Review:
runs-on: ubuntu-latest
steps:
# - name: ✅ Checkout PR code
# uses: actions/checkout@v3
- name: 🔍 Debug workspace structure
run: ls -R .github
- name: 🐍 Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'
- 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: |
# 确保 GITHUB_TOKEN 有权限读取 PR
PR_DIFF=$(gh pr view ${{ github.event.number }} --json files --jq '.files | map(.patch) | join("\n")')
# 将 diff 输出设置为一个环境变量
echo "PR_DIFF<<EOF" >> $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 }}
run: python .github/scripts/ai_code_review.py