đ #722
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| name: AI Moderator | |
| # **What it does**: Automatically detects spam in issues and comments using AI, | |
| # adds appropriate labels, and closes spam issues to reduce maintenance burden. | |
| # **Why we have it**: To automatically handle the high volume of spam issues | |
| # received on this repository without manual intervention. | |
| 'on': | |
| issues: | |
| types: [opened] | |
| issue_comment: | |
| types: [created] | |
| pull_request_review_comment: | |
| types: [created] | |
| jobs: | |
| spam-detection: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| models: read | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: AI Moderation | |
| uses: github/ai-moderator@6bcdb2a79c2e564db8d76d7d4439d91a044c4eb6 # v1.1.2 | |
| continue-on-error: true | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| spam-label: 'spam' | |
| ai-label: 'ai-generated' | |
| minimize-detected-comments: true | |
| # Enable all built-in detection methods | |
| enable-spam-detection: true | |
| enable-link-spam-detection: true | |
| enable-ai-detection: true | |
| close-spam-issues: | |
| runs-on: ubuntu-latest | |
| needs: spam-detection | |
| if: github.event_name == 'issues' && github.event.action == 'opened' | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Close spam issues | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| // Wait a moment for labels to be applied | |
| await new Promise(resolve => setTimeout(resolve, 5000)); | |
| // Get the issue to check for spam label | |
| const { data: issue } = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number | |
| }); | |
| // Check if issue has spam label | |
| const hasSpamLabel = issue.labels.some(label => | |
| label.name === 'spam' || label.name === 'ai-generated' | |
| ); | |
| if (hasSpamLabel) { | |
| // Close the issue | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| state: 'closed' | |
| }); | |
| // Add a comment explaining the closure | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: context.issue.number, | |
| body: 'This issue has been automatically closed as it was ' + | |
| 'detected as spam by our AI moderation system. If you ' + | |
| 'believe this was done in error, please contact the ' + | |
| 'repository maintainers.' | |
| }); | |
| console.log(`Closed issue #${context.issue.number} ` + | |
| `due to spam detection`); | |
| } |