|
| 1 | +name: Auto Close Invalid Issues |
| 2 | + |
| 3 | +on: |
| 4 | + issues: |
| 5 | + types: [opened] |
| 6 | + |
| 7 | +jobs: |
| 8 | + check-issue: |
| 9 | + runs-on: ubuntu-latest |
| 10 | + permissions: |
| 11 | + issues: write |
| 12 | + steps: |
| 13 | + - uses: actions/github-script@v7 |
| 14 | + env: |
| 15 | + ABUSIVE_WORDS: ${{ secrets.ABUSIVE_WORDS }} |
| 16 | + with: |
| 17 | + script: | |
| 18 | + const { owner, repo } = context.repo; |
| 19 | + const issue_number = context.payload.issue.number; |
| 20 | + const title = (context.payload.issue.title || '').toLowerCase(); |
| 21 | + const body = (context.payload.issue.body || '').toLowerCase(); |
| 22 | + const text = title + ' ' + body; |
| 23 | +
|
| 24 | + // --- 第一层:攻击性内容(词库存于 Secret: ABUSIVE_WORDS,逗号分隔)--- |
| 25 | + const abusiveWords = (process.env.ABUSIVE_WORDS || '').split(',').map(w => w.trim()).filter(Boolean); |
| 26 | + const isAbusive = abusiveWords.some(w => w && text.includes(w.toLowerCase())); |
| 27 | +
|
| 28 | + if (isAbusive) { |
| 29 | + await github.rest.issues.createComment({ |
| 30 | + owner, repo, issue_number, |
| 31 | + body: [ |
| 32 | + '你好,', |
| 33 | + '', |
| 34 | + '此 Issue 包含不文明内容,已自动关闭。', |
| 35 | + '', |
| 36 | + '我们欢迎任何建设性的反馈,但请保持礼貌和尊重。', |
| 37 | + '如有 Bug 或功能建议,请使用官方模板重新提交,谢谢。', |
| 38 | + ].join('\n'), |
| 39 | + }); |
| 40 | + await github.rest.issues.update({ |
| 41 | + owner, repo, issue_number, |
| 42 | + state: 'closed', |
| 43 | + state_reason: 'not_planned', |
| 44 | + }); |
| 45 | + await github.rest.issues.addLabels({ |
| 46 | + owner, repo, issue_number, |
| 47 | + labels: ['invalid'], |
| 48 | + }); |
| 49 | + return; |
| 50 | + } |
| 51 | +
|
| 52 | + // --- 第二层:未走模板 --- |
| 53 | + const templateMarkers = [ |
| 54 | + '### 运行平台', |
| 55 | + '### 问题描述', |
| 56 | + '### 复现步骤', |
| 57 | + '### 需求背景', |
| 58 | + '### 建议方案', |
| 59 | + ]; |
| 60 | + const isFromTemplate = templateMarkers.some(m => body.includes(m.toLowerCase())); |
| 61 | +
|
| 62 | + if (!isFromTemplate) { |
| 63 | + await github.rest.issues.createComment({ |
| 64 | + owner, repo, issue_number, |
| 65 | + body: [ |
| 66 | + '感谢你的反馈!', |
| 67 | + '', |
| 68 | + '此 Issue 未按照模板填写,已自动关闭。', |
| 69 | + '', |
| 70 | + '请使用以下方式重新提交:', |
| 71 | + '- 🐛 **Bug 报告** → 使用 [Bug 报告模板](../../issues/new?template=bug_report.yml)', |
| 72 | + '- 💡 **功能建议** → 使用 [功能建议模板](../../issues/new?template=feature_request.yml)', |
| 73 | + '- 💬 **使用咨询** → 前往 [Discussions](../../discussions) 提问', |
| 74 | + ].join('\n'), |
| 75 | + }); |
| 76 | + await github.rest.issues.update({ |
| 77 | + owner, repo, issue_number, |
| 78 | + state: 'closed', |
| 79 | + state_reason: 'not_planned', |
| 80 | + }); |
| 81 | + await github.rest.issues.addLabels({ |
| 82 | + owner, repo, issue_number, |
| 83 | + labels: ['invalid'], |
| 84 | + }); |
| 85 | + } |
0 commit comments