Umoren/github-triage-agent

★ 0Forks 0PythonGitHub ↗Compare

README

🤖 GitHub Issue Triage Agent (Python)

Python Flask GPT-4

An intelligent AI-powered GitHub issue triage agent that automatically classifies, labels, and comments on new issues using Python, Flask, and GPT-4.

Features

  • 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.

How It Works

  1. Webhook Reception: A Flask server listens for webhook events from a GitHub repository whenever a new issue is opened.
  2. Signature Verification: The server verifies the webhook payload's signature to ensure it originated from GitHub.
  3. Issue Processing: The issue details are passed to the TriageAgent.
  4. 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).
  5. 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.

Setup

Prerequisites

  1. Python 3.9+ and pip.
  2. GitHub Personal Access Token with repo scope.
  3. OpenAI API Key.
  4. A GitHub Repository to install the agent on.
  5. A Webhook Secret to secure the communication between GitHub and your agent.

Installation

  1. Clone the repository:

    git clone <this-repo>
    cd github-triage-agent
  2. 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
  3. Configure environment variables: Create a .env file 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
  4. 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 .env file.
    • Which events would you like to trigger this webhook?: Select "Issues".
    • Make sure the webhook is active.
  5. Create required labels in your GitHub repository. The agent will try to apply these labels, so they should exist:

    • bug
    • feature-request
    • documentation
    • question
    • enhancement

Running the Agent

# Activate the virtual environment
source venv/bin/activate

# Run the Flask application
python main.py

The server will start, typically on http://127.0.0.1:5000.

Environment Variables

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

License

MIT License

Contributors

Umoren

Issues