An AI-powered GitHub Action that automatically detects and moderates spam in issues and comments using GitHub Models language models.
Add this action to your repository's workflow file (e.g.,
.github/workflows/spam-guard.yml):
name: AI Spam Guard
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
steps:
- uses: actions/checkout@v4
- uses: github/ai-spam-guard
with:
token: ${{ secrets.GITHUB_TOKEN }}
spam-label: 'spam'
ai-label: 'ai-generated'| Input | Description | Default | Required |
|---|---|---|---|
token |
GitHub token with issues and pull-requests permissions | ${{ github.token }} |
No |
spam-label |
Label to add when generic spam is detected | spam |
No |
ai-label |
Label to add when AI-generated content is detected | ai-generated |
No |
The action no longer requires external API keys - it uses the built-in GitHub
token with models: read permission to access GitHub Models.
The action uses built-in YAML prompts located in the prompts/ directory:
spam-detection.prompt.yml: Detects promotional content, scams, and irrelevant postsai-detection.prompt.yml: Identifies AI-generated content patternsbot-detection.prompt.yml: Identifies automated bot behaviorlink-spam-detection.prompt.yml: Focuses on suspicious links and URLs
You can iterate on or tweak these prompts via the Models tab on this repository. If you want to push an update to this prompt, please also include updated test data so we can see the effect of the prompt update.
# Install dependencies
npm install
# Run tests
npm test
# Build the action
npm run package
# Run linting
npm run lintThe action includes comprehensive tests for all modules:
# Run all tests with coverage
npm run test
# Run tests in watch mode
npm run test:watch