Label Validator
Validate PR labels
The Label Validator ensures that pull requests have the required labels and don’t have forbidden labels. This helps categorize PRs correctly and enforce workflow stages.
Configuration
Must be set to "label"
Requirements for the number of labels
Minimum number of labels required
Maximum number of labels allowed
Label pattern(s) that must be present (supports regex)
Label pattern(s) that must not be present (supports regex)
Custom message to display when validation fails
Basic Usage
Examples
Required Labels
Ensure PRs have at least one specific label:
Forbidden Labels
Prevent merging PRs with certain labels:
Label Count
Enforce a minimum and maximum number of labels:
Pattern Matching
Use patterns to match label categories:
Combined Requirements
Combine multiple label requirements:
How It Works
Get Labels
The validator retrieves all labels currently applied to the PR
Check Count
If count
is specified, it verifies the number of labels meets requirements
Check Required Labels
If include
is specified, it checks that at least one matching label is present for each pattern
Check Forbidden Labels
If exclude
is specified, it checks that no matching labels are present
Return Result
Returns a validation result with status (pass, fail, or error) and a message
Pattern Matching
The Label Validator supports several pattern matching methods:
- Exact match:
"bug"
- Glob patterns:
"type-*"
- Regular expressions:
"/^type:.+$/"
(enclosed in forward slashes)
Practical Use Cases
PR Type Categorization
Ensure PRs are properly categorized:
Release Readiness
Validate that PRs are ready for release:
Changelog Categories
Enforce changelog categorization:
Component Labeling
Ensure changes are associated with specific components:
Best Practices
Don’t require too many labels, as it creates friction for contributors
Using with PR Creation Templates
To help contributors apply the right labels from the start, you can use GitHub’s PR template forms:
Then use GitHub Actions to apply labels based on the form inputs.