@@ -2,20 +2,35 @@ name: AI Code Review on PR
22
33on :
44 pull_request_target :
5- types : [labeled]
5+ types : [opened, synchronize, labeled]
66
77permissions :
88 contents : read
99 pull-requests : write
1010
1111jobs :
12- AI-Review :
13- if : github.event.label.name == 'pending-ai-review'
12+ ai-review :
1413 runs-on : ubuntu-latest
1514
1615 steps :
17- - name : 🔍 Debug workspace structure
18- run : ls -R .github
16+ - name : Check if label exists
17+ id : check_label
18+ uses : actions-ecosystem/action-get-labels@v1
19+ with :
20+ github_token : ${{ secrets.GITHUB_TOKEN }}
21+
22+ - name : Add label if missing
23+ if : contains(steps.check_label.outputs.labels, 'pending-ai-review') == false
24+ uses : actions-ecosystem/action-add-labels@v1
25+ with :
26+ github_token : ${{ secrets.GITHUB_TOKEN }}
27+ labels : pending-ai-review
28+
29+ - name : Stop if only labeling
30+ if : contains(steps.check_label.outputs.labels, 'pending-ai-review') == false
31+ run : |
32+ echo "Label added. Exiting."
33+ exit 0
1934
2035 - name : 🐍 Set up Python
2136 uses : actions/setup-python@v5
@@ -25,25 +40,11 @@ jobs:
2540 - name : 📦 Install dependencies
2641 run : pip install openai PyGithub
2742
28- - name : ✅ Checkout the default branch
43+ - name : ✅ Checkout PR
2944 uses : actions/checkout@v4
3045 with :
31- ref : ${{ github.event.pull_request.head.ref }}
3246 repository : ${{ github.event.pull_request.head.repo.full_name }}
33-
34- # - name: 🧾 Download PR diff via GitHub API
35- # id: pr_diff
36- # env:
37- # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
38- # GITHUB_REPOSITORY: ${{ github.repository }}
39- # PR_NUMBER: ${{ github.event.pull_request.number }}
40- # run: |
41- # # 确保 GITHUB_TOKEN 有权限读取 PR
42- # PR_DIFF=$(gh pr view ${{ github.event.number }} --json files --jq '.files | map(.patch) | join("\n")')
43- # # 将 diff 输出设置为一个环境变量
44- # echo "PR_DIFF<<EOF" >> $GITHUB_ENV
45- # echo "$PR_DIFF" >> $GITHUB_ENV
46- # echo "EOF" >> $GITHUB_ENV
47+ ref : ${{ github.event.pull_request.head.ref }}
4748
4849 - name : 🤖 Run AI code review
4950 env :
0 commit comments