-
Notifications
You must be signed in to change notification settings - Fork 0
63 lines (51 loc) · 1.72 KB
/
Copy pathsubmit-pr.yml
File metadata and controls
63 lines (51 loc) · 1.72 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
name: Submit PR Task
on:
issue_comment:
types: [created]
jobs:
submit:
runs-on: ubuntu-latest
steps:
- name: Handle /submit comment
uses: actions/github-script@v7
with:
script: |
const comment = context.payload.comment.body;
const issue_number = context.issue.number;
const owner = context.repo.owner;
const repo = context.repo.repo;
// 只处理 /submit
if (!comment.startsWith('/submit')) return;
const parts = comment.split(' ');
if (parts.length < 2) {
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `❌ 请提供 PR 链接`
});
return;
}
let pr = parts[1];
// 支持 owner/repo#123 格式
if (!pr.startsWith('http')) {
const [repoName, prNum] = pr.split('#');
pr = `https://github.com/${repoName}/pull/${prNum}`;
}
// 获取 Issue
const { data: issueData } = await github.rest.issues.get({
owner, repo, issue_number
});
let body = issueData.body || "";
// 更新 PR 字段
if (!body.includes("PR:")) {
body += `\nPR: ${pr}`;
} else {
body = body.replace(/PR:.*/g, `PR: ${pr}`);
}
await github.rest.issues.update({
owner, repo, issue_number, body
});
// 回复评论
await github.rest.issues.createComment({
owner, repo, issue_number,
body: `🚀 PR 已记录:${pr}`
});