-
Notifications
You must be signed in to change notification settings - Fork 35
91 lines (82 loc) · 3.48 KB
/
auto_process_issue.yml
File metadata and controls
91 lines (82 loc) · 3.48 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
91
# From MAA
# https://github.com/MaaAssistantArknights/MaaAssistantArknights/blob/dev/.github/workflows/issue-checkbox-checker.yml
# Use AGPL-3.0
# This copy has been modified.
name: Auto Close not reading issues or Fold checkboxes
on:
issues:
types: [opened]
jobs:
check-then-close-or-fold:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Check checkbox status
id: unread-checkbox-check
uses: actions/github-script@v6
with:
script: |
const texts = [
'我已在未仔细阅读这些内容的情况下勾选所有选项,并相信这不会影响问题的处理',
'I have checked all the options without carefully reading the content and believe this will not affect issue resolution.'];
return texts.some(text => new RegExp(`- \\[x\\]\\s*${text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}`).test(context.payload.issue.body));
- name: Comment and close issue
if: steps.unread-checkbox-check.outputs.result == 'true'
uses: actions/github-script@v6
with:
script: |
// 发送提示信息
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `由于你勾选了Trap Checkbox,请重新查看你的Checkbox,并确保你明白是否应该勾选该选项。`
});
// 关闭 issue
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed',
state_reason: 'not_planned'
});
// 锁定 issue
await github.rest.issues.lock({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
lock_reason: 'spam'
});
- name: Fold checkboxes
if: steps.unread-checkbox-check.outputs.result == 'false'
uses: actions/github-script@v6
with:
script: |
const originalBody = context.payload.issue.body;
const checkboxSectionRegex_cn_bug = /([\s\S]*?)(### 问题描述\n\n)/;
const checkboxSectionRegex_cn_feat = /([\s\S]*?)(### 说说你遇到的问题?\n\n)/;
const checkboxSectionRegex_en_bug = /([\s\S]*?)(### Description\n\n)/;
const checkboxSectionRegex_en_feat = /([\s\S]*?)(### The problems you have encountered?\n\n)/;
const foldedBody_cn_bug = originalBody.replace(
checkboxSectionRegex_cn_bug,
`<details><summary>Checkboxes</summary>\n\n$1\n\n</details>\n\n$2`
);
const foldedBody_cn_feat = foldedBody_cn_bug.replace(
checkboxSectionRegex_cn_feat,
`<details><summary>Checkboxes</summary>\n\n$1\n\n</details>\n\n$2`
);
const foldedBody_en_bug = foldedBody_cn_feat.replace(
checkboxSectionRegex_en_bug,
`<details><summary>Checkboxes</summary>\n\n$1\n\n</details>\n\n$2`
);
const foldedBody = foldedBody_en_bug.replace(
checkboxSectionRegex_en_feat,
`<details><summary>Checkboxes</summary>\n\n$1\n\n</details>\n\n$2`
);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: foldedBody
});