This document explains how to use and configure the automated PR review process in your repository.
The PR review automation system automatically:
- Assigns appropriate reviewers and assignees to pull requests based on branch patterns
- Tracks required review approvals from specific teams
- Updates PR status checks based on review requirements
- Enforces branch protection rules
- When a PR is opened or updated, the workflow triggers automatically
- The system reads your repository's
REVIEWERS.ymlfile - Based on the target branch, reviewers and assignees are assigned
- As reviews come in, the system tracks which teams have approved
- A status check shows whether all required approvals have been met
The review process is configured through the REVIEWERS.yml file in your repository's root. This file defines team-based review requirements for different branches.
pull_requests:
branches:
main:
review_teams:
- 'team-a-reviewers'
- 'team-a-project-owners'
assignees:
- 'team-a-developers'
required_approvals: 2
required_teams:
- 'team-a-reviewers'
- 'team-a-operations'You can use exact branch names or patterns with wildcards:
branches:
main:
# Configuration for main branch
"feature/*":
# Configuration for all feature branches
"release/*":
# Configuration for all release branchesThe system supports a {{ team_name }} variable that gets replaced with your repository's configured team name:
review_teams:
- '{{ team_name }}-reviewers'
- '{{ team_name }}-project-owners'Define which teams should be requested as reviewers:
review_teams:
- 'team-a-reviewers'
- 'team-a-project-owners'Important: Teams specified in
review_teamsmust be added as collaborators to the repository with at least "Read" permissions before they can be assigned as reviewers. GitHub will silently ignore review requests for teams that don't have repository access.
Define which teams should be assigned to the PR:
assignees:
- 'team-a-developers'Set the minimum number of approvals needed:
required_approvals: 2Specify which teams must approve before the PR can be merged:
required_teams:
- 'team-a-reviewers'
- 'team-a-operations'Exclude specific branches from a pattern:
"feature/*":
# Configuration here
exclude:
- "feature/do-not-assign"pull_requests:
branches:
main:
review_teams:
- '{{ team_name }}-reviewers'
- '{{ team_name }}-project-owners'
assignees:
- '{{ team_name }}-developers'
required_approvals: 2
required_teams:
- '{{ team_name }}-reviewers'
- '{{ team_name }}-operations'
"feature/*":
review_teams:
- '{{ team_name }}-testers'
- '{{ team_name }}-developers'
assignees:
- '{{ team_name }}-developers'
required_approvals: 1
required_teams:
- '{{ team_name }}-reviewers'
exclude:
- "feature/do-not-assign"For the review system to work properly, your organization should have teams set up following this pattern:
- Base team name: Configured as the
TEAM_NAMErepository variable - Role-specific teams: Append roles to the base name (e.g.,
-reviewers,-developers)
Example team structure:
team-a-reviewersteam-a-developersteam-a-project-ownersteam-a-operations
The workflow adds a status check called pr-review-requirements that shows:
- ✅ Success: All required team approvals have been received
- ⏱️ Pending: Still waiting for required team approvals
- No reviewers assigned: Check that your teams exist and have the exact names specified in REVIEWERS.yml
- Status check not updating: Ensure the workflow has proper permissions to create status checks
- Wrong teams assigned: Verify the
TEAM_NAMErepository variable is set correctly
If you need to troubleshoot the review process:
- Check the Actions tab in your repository
- Find the "Pull Request Approval Workflow" run
- View the logs for detailed information about the review assignment process
This document explains how to deploy and maintain the PR review process across multiple repositories.
The PR review system consists of:
Pull-Request-Approval-Workflow.yml- GitHub Actions workflowpr_review_manager.py- Python script that handles the review logicREVIEWERS.yml- Configuration file for team-based review rulesdeploy_pr_workflow.py- Deployment script to add the review system to repositories
Before deploying the review system, ensure:
- GitHub App: Create a GitHub App with repository and PR permissions
- Organization Teams: Set up teams for reviewers, developers, etc.
- Python Environment: Have Python 3.8+ with PyGithub installed
- Repository Variables: Set up the following secrets/variables in the source repository:
APP_ID: GitHub App IDAPP_KEY: GitHub App private keyPR_APP_ID: GitHub App ID for PR operationsPR_APP_KEY: GitHub App private key for PR operations
- Branch Protection Configuration: Ensure your branch protection rules allow the deployment:
- If you have branch protection rules for
feature/*branches, you must excludefeature/push_new_pr_update* - This exclusion is necessary because the deployment process creates this branch
- If you have branch protection rules for
For successful deployment across repositories with branch protection:
-
Exclude Deployment Branch: In any repository with branch protection on
feature/*patterns, add an exclusion for:feature/push_new_pr_updatefeature/push_new_pr_update-*(to cover randomly generated branch names when retrying)
-
Example Branch Protection Configuration:
- name: feature-branch-protection target: branch enforcement: active conditions: ref_name: include: ["refs/heads/feature/*"] exclude: ["refs/heads/feature/push_new_pr_update*"] # Allow deployment branch rules: # Your protection rules here
-
Organization-wide Settings: If using organization-wide branch protection settings, ensure:
- The GitHub App used for deployment has branch protection bypass permissions, OR
- The pattern
feature/push_new_pr_update*is excluded from protection rules
Failing to configure these exclusions will result in branch creation errors during deployment.
Use the deploy-pr-workflow.yml workflow from the GitHub Actions UI:
- Navigate to the Actions tab
- Select "Deploy PR Workflow and Config"
- Click "Run workflow"
- Enter parameters:
target_repositories: Comma-separated list of repos (e.g.,repo1:team1,repo2:team2)default_team_name: Default team name if not specified per repository
Run the deployment script directly:
# Set GitHub token
export GITHUB_TOKEN=your_token
export GITHUB_REPOSITORY=your_org/your_repo
# Deploy to multiple repositories
python scripts/deploy_pr_workflow.py "repo1:team1,repo2:team2" "Default-Team-Name"When you deploy the PR review system:
- A feature branch is created in each target repository
- The workflow file, Python script, and REVIEWERS.yml are added/updated
- A PR is opened to merge these changes into the target repository
- A repository variable
TEAM_NAMEis set based on your input
The target_repositories parameter accepts the following format:
repo1:team1,repo2:team2,repo3
Where:
repo1,repo2, etc. are repository namesteam1,team2, etc. are the base team names for each repository- Repositories without a team name use the default team name
The GitHub App used for deployment needs these permissions:
- Repository contents: Read & write
- Pull requests: Read & write
- Actions variables: Read & write
To update the review logic across all repositories:
- Make changes to
pr_review_manager.pyin the source repository - Run the deployment workflow to push updates to all target repositories
To update the GitHub Actions workflow:
- Modify
Pull-Request-Approval-Workflow.ymlin the source repository - Run the deployment workflow to push updates to all target repositories
To change the default review configuration:
- Update
REVIEWERS.ymlin the source repository - Run the deployment workflow to push the new configuration to target repositories
- Branch creation failures: Check that your token has repository creation permissions
- Variable setting failures: Ensure your token has permission to set repository variables
- PR creation failures: Verify your token has pull request creation permissions
- "Reference update failed" errors: Verify branch protection rules exclude
feature/push_new_pr_update*
The deployment script provides detailed logs for each step:
- Check the Actions tab for the "Deploy PR Workflow and Config" workflow run
- Review logs for specific error messages
- For manual deployments, check the console output
The deployment script includes retry logic for common issues:
- Branch creation retries with exponential backoff
- Unique branch name generation if conflicts occur
- Proper error handling for existing files/PRs
- Test on a single repository before deploying to multiple repositories
- Review PR content in target repositories before merging
- Set up branch protection rules to prevent bypassing the review requirements
- Document team structure to ensure reviewers know their responsibilities
- Monitor initial deployments to ensure the system works as expected