Skip to content

Commit ed96479

Browse files
committed
Merge branch '1.3.x'
2 parents bfb55ab + 4e391a7 commit ed96479

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

.github/workflows/anti-spam-filter.yml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Anti-Spam Filter
22

33
on:
44
issues:
5-
types: [ opened, edited ]
5+
types: [opened, edited]
66
pull_request:
7-
types: [ opened, edited ]
7+
types: [opened, edited]
88
issue_comment:
99
types: [created, edited]
1010
pull_request_review_comment:
@@ -23,31 +23,32 @@ jobs:
2323
- name: Run spam filter
2424
uses: actions/github-script@v7
2525
env:
26-
# The entire spam detection logic is stored here
2726
SPAM_DETECTION_SCRIPT: ${{ secrets.SPAM_DETECTION_SCRIPT }}
2827
with:
2928
script: |
30-
// Load and execute the spam detection script from secret
31-
const detectionScript = process.env.SPAM_DETECTION_SCRIPT;
32-
33-
if (!detectionScript) {
34-
core.warning("SPAM_DETECTION_SCRIPT secret not configured - skipping spam detection");
35-
core.info("To enable spam filtering, set up the SPAM_DETECTION_SCRIPT secret.");
36-
core.info("See documentation for setup instructions.");
37-
return;
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");
3841
}
39-
40-
try {
41-
// Execute the hidden script
42-
// The script has access to: github, context, core
43-
const detectSpam = eval(detectionScript);
44-
45-
// Run the detection
46-
await detectSpam(github, context, core);
47-
48-
} catch (err) {
49-
core.error(`Spam filter error: ${err.message}`);
50-
core.warning(`Filter execution failed - continuing without spam check`);
51-
// Don't fail the workflow, just log the error
42+
43+
// 调用工厂函数
44+
const detectSpam = factory({});
45+
46+
if (typeof detectSpam !== "function") {
47+
throw new Error("Factory did not return a function");
5248
}
53-
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)