π Integrating the GitHub PR Agent
This guide shows how to integrate the GitHub PR Agent into your GitHub Actions workflow to automatically generate and commit unit tests for pull requests.
β οΈ Requirementsβ
Before setting up the workflow:
- β Project must have a working Jest configuration
- β You must have a valid API key β Agent Fundamentals FAQ β
- β
Use a GitHub token with
pull-requests: write,contents: writeβ Token Permissions β - β Install dependencies before running the agent
- β
Use
NODE_OPTIONS: "--max-old-space-size=5120"β Memory Tuning β
π§© GitHub Actions Exampleβ
name: Early PR Test Generation
permissions:
contents: write
pull-requests: write
on:
pull_request:
types:
- opened
- reopened
branches:
- master
jobs:
early-test-generation:
runs-on: ubuntu-latest
steps:
- name: Checkout target repo
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Install dependencies
run: npm install
- name: Early PR Unit Test Generation Agent
id: early
uses: earlyai/pull-request-test-generation@v1
continue-on-error: true
env:
NODE_OPTIONS: "--max-old-space-size=5120"
with:
api-key: ${{ secrets.EARLY_SECRET_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
π Event Type Guidanceβ
Choose a pull request trigger based on your teamβs flow:
| Event Type | When It Runs | Recommended If... |
|---|---|---|
opened | When the PR is first created | Devs open PRs only after finishing work |
ready_for_review | When a draft PR is marked as ready | Devs use draft PRs during development |
synchronize | When commits are pushed to the PR branch | You want tests generated on every new commit |
β οΈ The agent checks all uncovered functions at 0% coverage every time it's triggered.
It does not persist state between runs.