Skip to main content
Integrate Codegen with GitHub Actions to automate code reviews, issue triage, and other development workflows. This guide shows you how to use the Codegen Python SDK within GitHub Actions workflows.
This approach is necessary because GitHub webhooks don’t fire for bot users, preventing direct @codegen mentions in automated workflows. Using GitHub Actions with the Codegen API provides a reliable alternative.

Prerequisites

Before setting up GitHub Actions with Codegen, ensure you have:
  • A GitHub repository with Actions enabled
  • A Codegen account with API access
  • Your organization ID and API token from codegen.com/developer
  • The Codegen GitHub App installed on your repository

Basic Setup

1. Store Your Credentials

Add your Codegen credentials as GitHub repository secrets:
  1. Go to your repository → Settings → Secrets and variables → Actions
  2. Add the following secrets:
    • CODEGEN_ORG_ID: Your organization ID from codegen.com/developer
    • CODEGEN_API_TOKEN: Your API token from codegen.com/developer

2. Create a GitHub Actions Workflow

Create .github/workflows/codegen-review.yml in your repository:

3. Create the Review Script

Create .github/scripts/codegen_review.py:

Advanced Configuration

Conditional Reviews

Only run reviews for specific conditions:

Custom Review Types

Create different review workflows for different scenarios:

Error Handling and Retries

Implement robust error handling:

Environment-Specific Workflows

Development Environment

Production Environment

Best Practices

Security

  • Never commit API tokens: Always use GitHub Secrets
  • Use least privilege: Create dedicated API tokens with minimal required permissions
  • Rotate tokens regularly: Update API tokens periodically
  • Monitor usage: Track API usage to detect anomalies

Performance

  • Set appropriate timeouts: Don’t let workflows run indefinitely
  • Use caching: Cache Python dependencies to speed up workflow execution
  • Parallel execution: Run multiple review types in parallel when possible
  • Rate limiting: Respect API rate limits to avoid throttling

Reliability

  • Implement retries: Handle transient failures gracefully
  • Add logging: Include detailed logging for debugging
  • Fail gracefully: Don’t block PRs if reviews fail
  • Monitor workflows: Set up alerts for workflow failures

Troubleshooting

Common Issues

Issue: “No repos found in the organization”
Issue: “Authentication failed”
Issue: “Task timeout”
Issue: “Workflow not triggering”

Debugging

Enable debug logging in your workflow:
Add debug output to your Python script:

Examples

Complete Working Example

Here’s a complete, production-ready workflow:

View Complete Example

See a full working example with all files and configurations in our examples repository.

Integration with Existing CI/CD

Integrate Codegen reviews with your existing CI/CD pipeline:

Next Steps