@@ -2,20 +2,35 @@ name: AI Code Review on PR
2
2
3
3
on :
4
4
pull_request_target :
5
- types : [labeled]
5
+ types : [opened, synchronize, labeled]
6
6
7
7
permissions :
8
8
contents : read
9
9
pull-requests : write
10
10
11
11
jobs :
12
- AI-Review :
13
- if : github.event.label.name == 'pending-ai-review'
12
+ ai-review :
14
13
runs-on : ubuntu-latest
15
14
16
15
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
19
34
20
35
- name : 🐍 Set up Python
21
36
uses : actions/setup-python@v5
@@ -25,25 +40,11 @@ jobs:
25
40
- name : 📦 Install dependencies
26
41
run : pip install openai PyGithub
27
42
28
- - name : ✅ Checkout the default branch
43
+ - name : ✅ Checkout PR
29
44
uses : actions/checkout@v4
30
45
with :
31
- ref : ${{ github.event.pull_request.head.ref }}
32
46
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 }}
47
48
48
49
- name : 🤖 Run AI code review
49
50
env :
0 commit comments