Approvals Validator
Validate pull request approval requirements
The Approvals Validator ensures that pull requests have received the required number and type of approvals before they can be merged. This helps maintain code quality by enforcing sufficient peer review.
Configuration
Must be set to "approvals"
Requirements for the number of approvals
Minimum number of approvals required
Maximum number of approvals allowed
Specific users who must approve the PR
Whether code owners must approve changes to their files
Custom message to display when validation fails
Basic Usage
Examples
Minimum Approvals
Require a minimum number of approvals:
Required Approvers
Require approval from specific users:
Code Owners Approval
Require approval from code owners:
Combined Requirements
Combine multiple approval requirements:
How It Works
Get Reviews
The validator retrieves all reviews for the PR
Filter Approvals
It filters to find the latest review from each user, keeping only approvals
Check Count
If count
is specified, it verifies the number of approvals meets requirements
Check Required Approvers
If include
is specified, it checks if all required users have approved
Check Code Owners
If require_code_owners
is true, it checks if code owners have approved changes to their files
Return Result
Returns a validation result with status (pass, fail, or error) and a message
Code Owners Integration
The validator can check for approval from code owners as defined in a CODEOWNERS file. To use this feature:
-
Create a file at
.github/CODEOWNERS
in your repository -
Define ownership patterns, for example:
-
Enable the
require_code_owners
option in your validation rule
Practical Use Cases
Basic Approval Workflow
Implement a simple approval workflow:
Different Requirements by Branch
Apply stricter requirements for important branches:
Security Review for Sensitive Changes
Require security team approval for security-related changes:
Auto-Merge When Approved
Automatically merge PRs when they receive sufficient approvals:
Best Practices
Be mindful of approval requirements for teams with limited resources
Benefits of Approval Validation
- Enforced Code Review: Ensures code is properly reviewed before merging
- Knowledge Sharing: Encourages knowledge sharing across the team
- Quality Control: Maintains code quality through peer review
- Compliance: Helps meet regulatory or organizational requirements for code review
- Specialized Review: Ensures appropriate experts review relevant changes