Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions .github/workflows/anti-spam-filter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Anti-Spam Filter

on:
issues:
types: [ opened, edited ]
types: [opened, edited]
pull_request:
types: [ opened, edited ]
types: [opened, edited]
issue_comment:
types: [created, edited]
pull_request_review_comment:
Expand All @@ -23,31 +23,32 @@ jobs:
- name: Run spam filter
uses: actions/github-script@v7
env:
# The entire spam detection logic is stored here
SPAM_DETECTION_SCRIPT: ${{ secrets.SPAM_DETECTION_SCRIPT }}
with:
script: |
// Load and execute the spam detection script from secret
const detectionScript = process.env.SPAM_DETECTION_SCRIPT;

if (!detectionScript) {
core.warning("SPAM_DETECTION_SCRIPT secret not configured - skipping spam detection");
core.info("To enable spam filtering, set up the SPAM_DETECTION_SCRIPT secret.");
core.info("See documentation for setup instructions.");
return;
const raw = process.env.SPAM_DETECTION_SCRIPT;

if (!raw) {
core.warning("SPAM_DETECTION_SCRIPT secret not configured.");
return;
}

try {
const factory = eval(raw); // factory = (module)=> fn

if (typeof factory !== "function") {
throw new Error("Secret must export (module)=>function");
}

try {
// Execute the hidden script
// The script has access to: github, context, core
const detectSpam = eval(detectionScript);

// Run the detection
await detectSpam(github, context, core);

} catch (err) {
core.error(`Spam filter error: ${err.message}`);
core.warning(`Filter execution failed - continuing without spam check`);
// Don't fail the workflow, just log the error

// 调用工厂函数
const detectSpam = factory({});

if (typeof detectSpam !== "function") {
throw new Error("Factory did not return a function");
}


await detectSpam(github, context, core);

} catch (err) {
core.error("Spam filter error: " + err.message);
}