Validation Types
Config Validators
Validate a setting by itself, regardless of context.Example: “No collaborator can have admin permission”
Override Validators
Validate when a lower-level config overrides a higher-level config.Example: “Required approvals cannot be decreased”
Basic Config Validator
Validate settings on their own, without considering overrides:deployment-settings.yml
- The
baseconfigvariable contains the collaborator setting being validated - Return
trueif validation passes,falseif it fails - The
errormessage is shown in PR checks and logs when validation fails - This validator runs every time a collaborator is configured
Basic Override Validator
Validate when settings are overridden at lower levels:deployment-settings.yml
baseconfigcontains the setting from org/suborg leveloverrideconfigcontains the setting from suborg/repo level that’s overriding it- Return
trueto allow the override,falseto reject it - This only runs when a setting is being overridden
Real-World Examples
Example 1: Enforce Team-Based Access
deployment-settings.yml
Example 2: Branch Protection Requirements
- Prevent Weakening Protection
- Enforce Minimum Protection
deployment-settings.yml
Example 3: Security and Compliance
deployment-settings.yml
Example 4: Naming Conventions
deployment-settings.yml
Example 5: Team Permission Policies
deployment-settings.yml
Advanced Validation Patterns
Context-Aware Validation
deployment-settings.yml
Multi-Field Validation
deployment-settings.yml
Conditional Validation
deployment-settings.yml
Complete Example
A comprehensive deployment-settings.yml with multiple validators:deployment-settings.yml
Testing Validators
When you create a PR with changed settings, Safe Settings runs in dry-run mode and executes all validators:Create PR with changes
Push your settings changes to a feature branch and create a PR to the default branch.
Review validation results
Safe Settings will comment on the PR showing:
- Which validators ran
- Which passed/failed
- Error messages for failed validators
- What changes would be applied if merged
Best Practices
Write clear error messages
Write clear error messages
Include:
- What went wrong
- Why it’s blocked
- How to fix it
Log validation decisions
Log validation decisions
Use
console.log() to help debug:Handle missing fields gracefully
Handle missing fields gracefully
Use optional chaining and defaults:
Keep validators simple
Keep validators simple
Each validator should check one thing. Multiple simple validators are better than one complex validator.
Document exceptions
Document exceptions
If you allow exceptions, document them:
Troubleshooting
Validator not running
Validator not running
Check:
- Validator is in
deployment-settings.ymlat the root where Safe Settings runs - Plugin name matches the setting type (
collaborators,teams,branches,repository,labels) - YAML syntax is valid (test with a YAML linter)
Validator always fails
Validator always fails
Debug:
- Add
console.log()statements to see what data you’re receiving - Check the Safe Settings logs or PR comments for your log output
- Verify field names match what’s in baseconfig/overrideconfig
- Test your logic with sample data
Override validator not triggering
Override validator not triggering
Check:
- Setting is actually being overridden (suborg/repo changes org setting)
- Plugin name is correct
- Both baseconfig and overrideconfig are checked (handle cases where either might be undefined)
Next Steps
Multi-Level Config
Learn how to structure configs that validators will check
Branch Protection
See what branch protection settings you can validate