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,
)
| 158 | """Information about the standardized commit message.""" |
| 159 | |
| 160 | def validate_commit_message( |
| 161 | self, |
| 162 | *, |
| 163 | commit_msg: str, |
| 164 | pattern: re.Pattern[str], |
| 165 | allow_abort: bool, |
| 166 | allowed_prefixes: list[str], |
| 167 | max_msg_length: int | None, |
| 168 | commit_hash: str, |
| 169 | ) -> ValidationResult: |
| 170 | """Validate commit message against the pattern.""" |
| 171 | if not commit_msg: |
| 172 | return ValidationResult( |
| 173 | allow_abort, [] if allow_abort else ["commit message is empty"] |
| 174 | ) |
| 175 | |
| 176 | if any(map(commit_msg.startswith, allowed_prefixes)): |
| 177 | return ValidationResult(True, []) |
| 178 | |
| 179 | if max_msg_length is not None and max_msg_length > 0: |
| 180 | msg_len = len(commit_msg.partition("\n")[0].strip()) |
| 181 | if msg_len > max_msg_length: |
| 182 | # TODO: capitalize the first letter of the error message for consistency in v5 |
| 183 | raise CommitMessageLengthExceededError( |
| 184 | f"commit validation: failed!\n" |
| 185 | f"commit message length exceeds the limit.\n" |
| 186 | f'commit "{commit_hash}": "{commit_msg}"\n' |
| 187 | f"message length limit: {max_msg_length} (actual: {msg_len})" |
| 188 | ) |
| 189 | |
| 190 | return ValidationResult( |
| 191 | bool(pattern.match(commit_msg)), |
| 192 | [f"pattern: {pattern.pattern}"], |
| 193 | ) |
| 194 | |
| 195 | def format_exception_message( |
| 196 | self, invalid_commits: list[tuple[git.GitCommit, list]] |
no test coverage detected