A GitHub PR Assistant powered by Motia.dev AI Agent Framework.

Close spammy PRs intelligently - This GitHub App automatically monitors pull requests, posts comments, and closes if they are spammy (based on conditions you decide).
- 🧠 Posts automated contextual comments on Pull Requests
- 🛑 Closes PRs based on custom logic that you can define and change
- 🧩 Listens to GitHub webhook events using a local server
- 🚀 Uses OpenAI to analyse PRs and generate intelligent messages
- ☝️ Uses PR diffs to analyse PRs and matches PR title/description with the diff, so that the comments are always contextual
- 💡 Built entirely using Motia.dev to showcase how fast you can go from zero to awesome!
You'll need the following before running this locally:
- Node.js ≥ 18.x and npm
- ngrok (for webhook tunneling)
- A GitHub account
- A GitHub App of your own
- An OpenAI API key
-
Clone the repository:
git clone https://github.com/sumitsaurabh927/Spamurai-pr-agent cd spamurai -
Install dependencies:
pnpm install
-
Create a
.envfile in the root directory (see Environment Variables section). -
Start your application server:
pnpm start
-
Run ngrok to expose your local server:
ngrok http 3000
-
Create and configure your GitHub App (see GitHub App Setup section).
-
Update the webhook URL in your GitHub App settings with your ngrok URL.
-
Install the app on your desired repository.
| Step | ✅ Done |
|---|---|
| Clone repo | ☑️ |
| Install dependencies | ☑️ |
| Create GitHub App | ☑️ |
| Set permissions + webhook events | ☑️ |
Create .env file |
☑️ |
| Start your app | ☑️ |
| Run ngrok | ☑️ |
| Update webhook URL | ☑️ |
| Install app on a repo | ☑️ |
Create a .env file in the project root with the following variables:
GITHUB_WEBHOOK_SECRET=your_webhook_secret
GITHUB_PAT=your_personal_access_token
GITHUB_APP_ID=your_github_app_id
GITHUB_PRIVATE_KEY=-----BEGIN RSA PRIVATE KEY-----\n...\n-----END RSA PRIVATE KEY-----
OPENAI_API_KEY=your_openai_api_key
Notes:
- For
GITHUB_PRIVATE_KEY, make sure to include the entire RSA key with newlines replaced by\n. You can convert it using this command:awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;}' private-key.pem - Generate a random string for
GITHUB_WEBHOOK_SECRET(you'll use this when setting up the GitHub App)
-
Go to your GitHub Developer Settings
-
Click "New GitHub App" and fill in the details:
- Name: Give your app a unique name (Spamurai)
- Homepage URL: Your project's homepage or repository URL
- Webhook URL: Your ngrok URL (see below) +
/webhooks/github(e.g.,https://5316-2401-4900-4e7e-90f5-5d65-9a3f-9f74-787f.ngrok-free.app/webhooks/github) - Webhook Secret: The same value you used for
GITHUB_WEBHOOK_SECRET
-
Set the required permissions:
- Repository permissions:
- Contents: Read & write
- Issues: Read & write
- Pull requests: Read & write
- Metadata: Read-only (mandatory)
- Repository permissions:
-
Subscribe to the following events:
- Issue comment
- Pull request
- Pull request review
- Push
-
After creating the app, note your App ID and generate a private key (download it).
For local development, you need to expose your local server to the internet using ngrok:
-
Start your application server:
pnpm start
-
In a new terminal, start ngrok:
ngrok http 3000
-
Copy the HTTPS forwarding URL (e.g.,
https://5316-2401-4900-4e7e-90f5-5d65-9a3f-9f74-787f.ngrok-free.app) -
Update your GitHub App's webhook URL with this ngrok URL +
/webhooks/github -
Install the app on your desired repository (from the app's settings page).
Note: The ngrok URL changes each time you restart ngrok unless you have a paid account. Update your GitHub App's webhook URL whenever it changes.
After setup, Spamurai will automatically:
- Listen for webhook events from GitHub
- Process events according to the Motia.dev agent workflows
- Perform actions like commenting on PRs or closing them based on configured rules
The app demonstrates how to build AI-powered GitHub automation using the Motia.dev framework.
Spamurai leverages the Motia.dev AI Agent Framework to:
- Create intelligent workflows that respond to GitHub events
- Generate contextually relevant PR comments using OpenAI
- Make smart decisions about PR management based on content analysis
- Showcase how engineers can build AI-powered tools with minimal overhead
Visit Motia.dev to learn more about building your own AI-powered developer tools.
- Verify your ngrok URL is correctly set in the GitHub App settings
- Check that the webhook secret matches between GitHub and your
.envfile - Ensure your app is installed on the repository you're testing with
- Verify your
GITHUB_APP_IDandGITHUB_PRIVATE_KEYare correct - Check that your app has the necessary permissions
- Review GitHub's webhook documentation for event payloads
- Add logging to see the incoming webhook data
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
├── services/
│ ├── github # GitHub API integration
│ └── openai # OpenAI API integration
├── steps/
│ ├── pr-webhook # Handles incoming PR webhook events from GitHub to detect and respond to spammy PRs
│ └── spam-detection # Checks the PR for spamminess
│ └── comment # Post a contextual and intelligent comment
│ └── pr-closer # Close a PR if found spammy
│ └── noop # Simulates GitHub PR webhook events to test Spamurai flow
├── types/ # enums for the project
└── ...
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Note: This project is a demonstration of Motia.dev capabilities. For production use, consider implementing additional security and scaling features. Learn more at Motia docs, and join our Discord to ask questions and talk to the Motia community.