@@ -27,20 +27,31 @@ jobs:
2727 - name : 📦 Install dependencies
2828 run : pip install openai requests
2929
30+ - name : ✅ Checkout the default branch
31+ uses : actions/checkout@v4
32+ with :
33+ # 在 pull_request_target 事件中,我们必须手动检出 PR 提交的代码
34+ # 否则它会检出主分支的代码,导致审查的是主分支而非PR分支
35+ ref : ${{ github.event.pull_request.h ead.sha }}
36+
3037 - name : 🧾 Download PR diff via GitHub API
38+ id : pr_diff
3139 env :
3240 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
3341 GITHUB_REPOSITORY : ${{ github.repository }}
3442 PR_NUMBER : ${{ github.event.pull_request.number }}
3543 run : |
36- curl -s -H "Authorization: token $GITHUB_TOKEN" \
37- -H "Accept: application/vnd.github.v3.diff" \
38- https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER \
39- -o pr.diff
44+ # 确保 GITHUB_TOKEN 有权限读取 PR
45+ PR_DIFF=$(gh pr view ${{ github.event.number }} --json files --jq '.files | map(.patch) | join("\n")')
46+ # 将 diff 输出设置为一个环境变量
47+ echo "PR_DIFF<<EOF" >> $GITHUB_ENV
48+ echo "$PR_DIFF" >> $GITHUB_ENV
49+ echo "EOF" >> $GITHUB_ENV
4050
4151 - name : 🤖 Run AI code review
4252 env :
4353 OPENAI_API_KEY : ${{ secrets.OPENAI_API_KEY }}
54+ OPENAI_API_ENDPOINT : ${{ secrets.OPENAI_API_ENDPOINT }}
4455 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4556 GITHUB_REPOSITORY : ${{ github.repository }}
4657 PR_NUMBER : ${{ github.event.pull_request.number }}
0 commit comments