Skip to main content
This tutorial demonstrates how to build an intelligent GitHub PR review bot that automatically reviews pull requests when triggered by labels. The bot uses Codegen’s GitHub integration and AI capabilities to provide comprehensive code reviews with actionable feedback.
View the full code and setup instructions in our examples repository
The bot is triggered by adding a “Codegen” label to PRs, making it easy to integrate into your existing workflow

Overview

The process involves three main components:
  1. Setting up a Modal web endpoint for GitHub webhooks
  2. Handling PR label events
  3. Running an AI-powered code review agent
Let’s walk through each component using Codegen.

Step 1: Setting Up the Modal App

First, we set up a Modal application to handle GitHub webhooks:
The Modal app provides a webhook endpoint that GitHub can call when PR events occur. Make sure to configure your GitHub repository’s webhook settings to point to your Modal endpoint.

Step 2: Handling PR Events

Next, we set up event handlers for PR label events:
The bot only triggers on PRs labeled with “Codegen”, giving you control over which PRs get reviewed.

Step 3: Implementing the Review Agent

Finally, we implement the AI-powered review agent:

Setting Up the Environment

Before running the bot, you’ll need:
  1. Create a .env file with your credentials:
  1. Deploy the Modal app:
  1. Configure GitHub webhook:
    • Go to your repository settings
    • Add webhook pointing to your Modal endpoint
    • Select “Pull request” events
    • Add a webhook secret (optional but recommended)

Example Usage

  1. Create or update a pull request in your repository
  2. Add the “Codegen” label to trigger a review
  3. The bot will:
    • Post a temporary “starting review” comment
    • Analyze the PR changes
    • Post detailed review comments
    • Remove the temporary comment when done
To remove the bot’s comments:
  1. Remove the “Codegen” label
  2. The bot will automatically clean up its comments

Extensions

While this example demonstrates a basic PR review bot, you can extend it to:
  • Customize the review criteria
  • Add more sophisticated analysis tools
  • Integrate with other services
  • Add automatic fix suggestions
  • … etc.
Check out our Code Agent tutorial to learn more about building sophisticated AI agents with Codegen