Skip to content

Commit 73cd52b

Browse files
authored
[framework] Add anti spam filter (#381)
1 parent 1e0f019 commit 73cd52b

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Anti-Spam Filter
2+
3+
on:
4+
issues:
5+
types: [opened, edited]
6+
pull_request:
7+
types: [opened, edited]
8+
issue_comment:
9+
types: [created, edited]
10+
pull_request_review_comment:
11+
types: [created, edited]
12+
13+
permissions:
14+
issues: write
15+
pull-requests: write
16+
contents: write
17+
18+
jobs:
19+
moderate:
20+
if: ${{ github.event.action == 'created' || github.event.action == 'edited' || github.event.action == 'opened' }}
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Run spam filter
24+
uses: actions/github-script@v7
25+
env:
26+
SPAM_DETECTION_SCRIPT: ${{ secrets.SPAM_DETECTION_SCRIPT }}
27+
with:
28+
script: |
29+
const raw = process.env.SPAM_DETECTION_SCRIPT;
30+
31+
if (!raw) {
32+
core.warning("SPAM_DETECTION_SCRIPT secret not configured.");
33+
return;
34+
}
35+
36+
try {
37+
const factory = eval(raw); // factory = (module)=> fn
38+
39+
if (typeof factory !== "function") {
40+
throw new Error("Secret must export (module)=>function");
41+
}
42+
43+
// 调用工厂函数
44+
const detectSpam = factory({});
45+
46+
if (typeof detectSpam !== "function") {
47+
throw new Error("Factory did not return a function");
48+
}
49+
50+
await detectSpam(github, context, core);
51+
52+
} catch (err) {
53+
core.error("Spam filter error: " + err.message);
54+
}

0 commit comments

Comments
 (0)