An intelligent AI-powered GitHub issue triage agent that automatically classifies, labels, and comments on new issues using Python, Flask, and GPT-4.
- AI-Powered Classification: Uses GPT-4 Turbo for intelligent issue categorization.
- Automatic Labeling: Applies appropriate labels based on AI analysis.
- Smart Comments: Generates detailed triage explanations.
- Secure Webhooks: Validates GitHub webhook signatures for secure communication.
- Real-time Processing: Instantly triages new issues as they are created.
- Extensible: Built with a clear structure using Flask and a dedicated triage agent class.
- Webhook Reception: A Flask server listens for webhook events from a GitHub repository whenever a new issue is opened.
- Signature Verification: The server verifies the webhook payload's signature to ensure it originated from GitHub.
- Issue Processing: The issue details are passed to the
TriageAgent. - AI Classification: The agent sends the issue title and body to the OpenAI API (or a compatible service) to determine the issue's nature (e.g., bug, feature request).
- Labeling and Commenting: Based on the AI's response, the agent uses the GitHub API to add the appropriate labels and post a comment on the issue.
- Python 3.9+ and
pip. - GitHub Personal Access Token with
reposcope. - OpenAI API Key.
- A GitHub Repository to install the agent on.
- A Webhook Secret to secure the communication between GitHub and your agent.
-
Clone the repository:
git clone <this-repo> cd github-triage-agent
-
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate` pip install -r requirements.txt
-
Configure environment variables: Create a
.envfile in the project root and add the following variables. You can copy the example below.# .env GITHUB_WEBHOOK_SECRET=your_webhook_secret GITHUB_TOKEN=your_github_personal_access_token GITHUB_REPO_OWNER=owner_of_the_repo GITHUB_REPO_NAME=name_of_the_repo OPENAI_API_KEY=your_openai_api_key
-
Set up the GitHub Webhook:
- Go to your target GitHub repository's Settings > Webhooks.
- Click Add webhook.
- Payload URL: Set this to the public URL where your Flask app will be running (e.g.,
https://your-domain.com/webhook). For local development, you can use a tool like ngrok to expose your local server to the internet. - Content type:
application/json. - Secret: Use the same secret you defined in your
.envfile. - Which events would you like to trigger this webhook?: Select "Issues".
- Make sure the webhook is active.
-
Create required labels in your GitHub repository. The agent will try to apply these labels, so they should exist:
bugfeature-requestdocumentationquestionenhancement
# Activate the virtual environment
source venv/bin/activate
# Run the Flask application
python main.pyThe server will start, typically on http://127.0.0.1:5000.
| Variable | Description | Required |
|---|---|---|
GITHUB_WEBHOOK_SECRET |
The secret used to verify GitHub webhooks. | Yes |
GITHUB_TOKEN |
A GitHub Personal Access Token with repo scope. |
Yes |
GITHUB_REPO_OWNER |
The username or organization that owns the repo. | Yes |
GITHUB_REPO_NAME |
The name of the repository. | Yes |
OPENAI_API_KEY |
Your API key for the OpenAI service. | Yes |
FLASK_DEBUG |
Enables debug mode for the Flask app (e.g., 1). |
No |
MIT License