返回 CodeWhale
spam-lockdown.yml
根目录 / .github / workflows / spam-lockdown.yml
1 name: Lock down obvious spam issues
2
3 on:
4 issues:
5 types: [opened]
6
7 permissions:
8 issues: write
9
10 jobs:
11 lockdown:
12 if: ${{ !contains(github.event.issue.labels.*.name, 'contribution') }}
13 runs-on: ubuntu-24.04
14 timeout-minutes: 10
15 steps:
16 - name: Auto-close spam patterns from new accounts
17 uses: actions/github-script@v9
18 with:
19 script: |
20 const issue = context.payload.issue;
21 const author = issue.user;
22
23 // Only consider brand-new accounts. If the user has been around
24 // long enough to file good-faith issues elsewhere, don't touch.
25 const created = new Date(author.created_at || 0);
26 const ageDays = (Date.now() - created.getTime()) / 86_400_000;
27 if (ageDays > 30) return;
28
29 const blob = `${issue.title || ''}\n${issue.body || ''}`;
30 const patterns = [
31 /\btg\s*@/i,
32 /\btelegram\s+@/i,
33 /\bt\.me\//i,
34 /\bwhatsapp\s+\+/i,
35 /\bseo\s+service/i,
36 /\bguest\s+post/i,
37 /\bbacklink/i,
38 /\bbuy\s+followers/i,
39 ];
40 const hit = patterns.find(p => p.test(blob));
41 if (!hit) return;
42
43 // Label and close; no comment (founder, 2026-09-22). The label
44 // description tells a false positive how to get the issue back.
45 try {
46 await github.rest.issues.createLabel({
47 owner: context.repo.owner,
48 repo: context.repo.repo,
49 name: 'spam',
50 color: 'b60205',
51 description: 'Auto-closed: spam pattern from a <30-day account. Real report? Reopen with project context',
52 });
53 } catch (error) {
54 if (error.status !== 422) throw error; // 422: label already exists
55 }
56
57 await github.rest.issues.update({
58 owner: context.repo.owner,
59 repo: context.repo.repo,
60 issue_number: issue.number,
61 state: 'closed',
62 state_reason: 'not_planned',
63 });
64
65 await github.rest.issues.addLabels({
66 owner: context.repo.owner,
67 repo: context.repo.repo,
68 issue_number: issue.number,
69 labels: ['spam'],
70 });
71
71 lines YAML