Files Filter
Filter rules based on modified files
The Files Filter allows you to apply rules only when specific files are modified in a pull request. This is useful for creating targeted rules that apply only to certain parts of your codebase.
Configuration
Must be set to "files"
Conditions for added files
File patterns that should match for added files
File patterns that should not match for added files
Conditions for modified files
File patterns that should match for modified files
File patterns that should not match for modified files
Basic Usage
Examples
Match Specific Files
Apply a rule Apply a rule only when specific files are modified:
Match File Types
Apply a rule based on file types:
Match Files in Directory
Apply a rule only when files in a specific directory are changed:
Ignore Certain Files
Apply a rule only when meaningful files are changed (ignoring configuration files):
Added Files Only
Apply a rule only when new files are added:
Pattern Matching
The Files Filter supports several pattern matching methods:
- Exact match:
"package.json"
- Glob patterns:
"src/**/*.js"
- Regular expressions:
"/^src\/.*\.jsx?$/"
(enclosed in forward slashes)
How It Works
Get Changed Files
The filter retrieves all files changed in the PR, categorized by change type (added, modified, deleted)
Process Added Files
If added
conditions are specified, it checks if added files match the required patterns
Process Modified Files
If modified
conditions are specified, it checks if modified files match the required patterns
Determine Match
Returns a match result indicating whether the specified file patterns were found
Practical Use Cases
Component-Specific Rules
Apply different rules based on the type of components changed:
Security Review for Sensitive Files
Require special handling for security-sensitive changes:
Different Requirements by File Type
Apply different validation rules based on file type:
Automatic Labeling
Automatically label PRs based on changed files:
Best Practices
Overly complex patterns can be difficult to maintain; keep them as simple as possible
Pattern Examples
Here are some common pattern examples:
Pattern | Matches |
---|---|
src/.* | All files in the src directory and subdirectories |
.*\\.js$ | All JavaScript files |
.*\\.(js|ts)$ | All JavaScript and TypeScript files |
src/components/.* | All files in src/components and subdirectories |
package\\.json | Only the root package.json file |
/^docs\/api\/.*\.md$/ | Markdown files in the docs/api directory |