forked from deepmodeling/DeePTB
-
Notifications
You must be signed in to change notification settings - Fork 1
90 lines (81 loc) · 2.95 KB
/
Copy pathpr_review_plan_comment.yml
File metadata and controls
90 lines (81 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: PR Review Plan Comment
on:
pull_request_target:
types: [opened, synchronize, reopened]
jobs:
review-plan-comment:
name: Comment advisory PR review plan
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout trusted base code
uses: actions/checkout@v7
with:
# Keep the workflow and helper script versions in sync while avoiding fork code.
ref: ${{ github.event.pull_request.base.ref }}
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.11"
- name: Get changed files
uses: actions/github-script@v9
with:
script: |
const files = await github.paginate(
github.rest.pulls.listFiles,
{
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number,
per_page: 100,
}
);
const names = files.map((file) => file.filename).join("\n");
require("fs").writeFileSync("changed-files.txt", names);
- name: Generate review plan
run: |
python scripts/ci/pr_review_plan.py --stdin --format github-comment < changed-files.txt > pr-review-plan.md
- name: Comment review plan
uses: actions/github-script@v9
with:
script: |
const fs = require("fs");
const marker = "<!-- deeptb-pr-review-plan -->";
const plan = fs.readFileSync("pr-review-plan.md", "utf8");
const body = [
marker,
"This advisory review plan was generated from changed file names using trusted base-branch code.",
"此审查计划由受信任的 base 分支代码根据变更文件名生成,仅作为维护者辅助。",
"",
plan,
].join("\n");
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
per_page: 100,
}
);
const previous = comments.find((comment) =>
comment.user.type === "Bot" && comment.body.includes(marker)
);
if (previous) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: previous.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body,
});
}