๐ 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โ
- JavaScript / TypeScript
- Python
- โ 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 โ
- โ Python 3.11+ and Node.js 20+ must be available
- โ
Both
@earlyai/cli(npm) andpy-agent(pip) must be installed - โ You must have a valid API key โ Agent Fundamentals FAQ โ
- โ
Use a GitHub token with
pull-requests: write,contents: writeโ Token Permissions โ - โ Install project dependencies before running the agent
๐งฉ GitHub Actions Exampleโ
- JavaScript / TypeScript
- Python
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 clean-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 }}
name: Early PR Test Generation
permissions:
contents: write
pull-requests: write
packages: read
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 }}
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install project dependencies
run: pip install -r requirements.txt
- name: Install Early CLI and py-agent
run: |
npm install -g @earlyai/cli
pip install py-agent
- name: Early PR Test Generation
continue-on-error: true
env:
API_KEY: ${{ secrets.EARLY_API_KEY }}
TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
REF_NAME: ${{ github.head_ref }}
BASE_REF: ${{ github.base_ref }}
TEST_FRAMEWORK: pytest
MAX_CONCURRENCY: "3"
run: early generate-pr
Note: Unlike JavaScript/TypeScript which uses the GitHub Marketplace action, Python uses the Early CLI directly with
early generate-pr.
๐ 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.