Commit Validator
Validate commit message format and content
The Commit Validator ensures that commit messages in a pull request follow specified patterns or formats, helping maintain a consistent commit history in your repository.
Configuration
Must be set to "commit"
Regex pattern(s) that commit messages should match
Regex pattern(s) for commit messages to ignore
Skip validation for merge commits (starting with “Merge ”)
Only validate the first commit in the PR
Only validate the last commit in the PR
Custom message to display when validation fails
Basic Usage
Examples
Conventional Commits Format
Validate that commit messages follow the Conventional Commits format:
Issue Reference Required
Ensure commits reference an issue number:
Validate Only the Last Commit
For squash-and-merge workflows, you might only care about the last commit:
Ignore Certain Commit Patterns
Skip validation for certain types of commits:
Pattern Matching
The Commit Validator uses JavaScript regular expressions for pattern matching. When specifying patterns, remember:
- Patterns are case-sensitive by default
- Some characters need to be escaped with a backslash (
\
) - In YAML, backslashes need to be double escaped (
\\
)
For case-insensitive matching, use the i
flag: "/pattern/i"
How It Works
Retrieve Commits
The validator fetches all commits in the PR from the GitHub API
Filter Commits
Applies filtering based on ignore_merge_commits
, first_only
, or last_only
settings
Check Patterns
For each commit, checks if the message matches required patterns and doesn’t match ignored patterns
Return Result
Returns a validation result with status (pass, fail, or error) and a message listing any non-conforming commits
Complete Rule Example
Best Practices
ignore_merge_commits
to avoid validation errors on automated merge commitslast_only: true
Complex validation rules may be frustrating for contributors; consider providing commit message templates