|
7 | 7 |
|
8 | 8 | from commitizen import commands, git |
9 | 9 | from commitizen.cz import registry |
10 | | -from commitizen.cz.base import BaseCommitizen, ValidationResult |
| 10 | +from commitizen.cz.base import BaseCommitizen |
11 | 11 | from commitizen.exceptions import ( |
12 | 12 | CommitMessageLengthExceededError, |
13 | 13 | InvalidCommandArgumentError, |
|
16 | 16 | ) |
17 | 17 |
|
18 | 18 | if TYPE_CHECKING: |
19 | | - import re |
20 | 19 | from collections.abc import Mapping |
21 | 20 |
|
22 | 21 | from pytest_mock import MockFixture, MockType |
@@ -385,7 +384,7 @@ def test_check_command_cli_overrides_config_message_length_limit( |
385 | 384 | ): |
386 | 385 | message = "fix(scope): some commit message" |
387 | 386 | config.settings["message_length_limit"] = len(message) - 1 |
388 | | - for message_length_limit in [len(message) + 1, None]: |
| 387 | + for message_length_limit in [len(message) + 1, 0]: |
389 | 388 | success_mock.reset_mock() |
390 | 389 | commands.Check( |
391 | 390 | config=config, |
@@ -419,60 +418,6 @@ def example(self) -> str: |
419 | 418 | def info(self) -> str: |
420 | 419 | return "Commit message must start with an issue number like ABC-123" |
421 | 420 |
|
422 | | - def validate_commit_message( |
423 | | - self, |
424 | | - *, |
425 | | - commit_msg: str, |
426 | | - pattern: re.Pattern[str], |
427 | | - allow_abort: bool, |
428 | | - allowed_prefixes: list[str], |
429 | | - max_msg_length: int | None, |
430 | | - commit_hash: str, |
431 | | - ) -> ValidationResult: |
432 | | - """Validate commit message against the pattern.""" |
433 | | - if not commit_msg: |
434 | | - return ValidationResult( |
435 | | - allow_abort, [] if allow_abort else ["commit message is empty"] |
436 | | - ) |
437 | | - |
438 | | - if any(map(commit_msg.startswith, allowed_prefixes)): |
439 | | - return ValidationResult(True, []) |
440 | | - |
441 | | - if max_msg_length: |
442 | | - msg_len = len(commit_msg.partition("\n")[0].strip()) |
443 | | - if msg_len > max_msg_length: |
444 | | - # TODO: capitalize the first letter of the error message for consistency in v5 |
445 | | - raise CommitMessageLengthExceededError( |
446 | | - f"commit validation: failed!\n" |
447 | | - f"commit message length exceeds the limit.\n" |
448 | | - f'commit "{commit_hash}": "{commit_msg}"\n' |
449 | | - f"message length limit: {max_msg_length} (actual: {msg_len})" |
450 | | - ) |
451 | | - |
452 | | - return ValidationResult( |
453 | | - bool(pattern.match(commit_msg)), [f"pattern: {pattern.pattern}"] |
454 | | - ) |
455 | | - |
456 | | - def format_exception_message( |
457 | | - self, invalid_commits: list[tuple[git.GitCommit, list]] |
458 | | - ) -> str: |
459 | | - """Format commit errors.""" |
460 | | - displayed_msgs_content = "\n".join( |
461 | | - [ |
462 | | - ( |
463 | | - f'commit "{commit.rev}": "{commit.message}"\nerrors:\n\n'.join( |
464 | | - f"- {error}" for error in errors |
465 | | - ) |
466 | | - ) |
467 | | - for (commit, errors) in invalid_commits |
468 | | - ] |
469 | | - ) |
470 | | - return ( |
471 | | - "commit validation: failed!\n" |
472 | | - "please enter a commit message in the commitizen format.\n" |
473 | | - f"{displayed_msgs_content}" |
474 | | - ) |
475 | | - |
476 | 421 |
|
477 | 422 | @pytest.fixture |
478 | 423 | def use_cz_custom_validator(mocker): |
|
0 commit comments