Validate commit message against the pattern.
(
self,
*,
commit_msg: str,
pattern: re.Pattern[str],
allow_abort: bool,
allowed_prefixes: list[str],
max_msg_length: int | None,
commit_hash: str,
)
| 112 | """Information about the standardized commit message.""" |
| 113 | |
| 114 | def validate_commit_message( |
| 115 | self, |
| 116 | *, |
| 117 | commit_msg: str, |
| 118 | pattern: re.Pattern[str], |
| 119 | allow_abort: bool, |
| 120 | allowed_prefixes: list[str], |
| 121 | max_msg_length: int | None, |
| 122 | commit_hash: str, |
| 123 | ) -> ValidationResult: |
| 124 | """Validate commit message against the pattern.""" |
| 125 | if not commit_msg: |
| 126 | return ValidationResult( |
| 127 | allow_abort, [] if allow_abort else ["commit message is empty"] |
| 128 | ) |
| 129 | |
| 130 | if any(map(commit_msg.startswith, allowed_prefixes)): |
| 131 | return ValidationResult(True, []) |
| 132 | |
| 133 | if max_msg_length is not None and max_msg_length > 0: |
| 134 | msg_len = len(commit_msg.partition("\n")[0].strip()) |
| 135 | if msg_len > max_msg_length: |
| 136 | # TODO: capitalize the first letter of the error message for consistency in v5 |
| 137 | raise CommitMessageLengthExceededError( |
| 138 | f"commit validation: failed!\n" |
| 139 | f"commit message length exceeds the limit.\n" |
| 140 | f'commit "{commit_hash}": "{commit_msg}"\n' |
| 141 | f"message length limit: {max_msg_length} (actual: {msg_len})" |
| 142 | ) |
| 143 | |
| 144 | return ValidationResult( |
| 145 | bool(pattern.match(commit_msg)), |
| 146 | [f"pattern: {pattern.pattern}"], |
| 147 | ) |
| 148 | |
| 149 | def format_exception_message( |
| 150 | self, invalid_commits: list[tuple[git.GitCommit, list]] |
no test coverage detected