|
2 | 2 |
|
3 | 3 | import re
|
4 | 4 | import sys
|
5 |
| -from typing import Any |
| 5 | +from typing import TypedDict |
6 | 6 |
|
7 | 7 | from commitizen import factory, git, out
|
8 | 8 | from commitizen.config import BaseConfig
|
|
13 | 13 | )
|
14 | 14 |
|
15 | 15 |
|
| 16 | +class CheckArgs(TypedDict, total=False): |
| 17 | + commit_msg_file: str |
| 18 | + commit_msg: str |
| 19 | + rev_range: str |
| 20 | + allow_abort: bool |
| 21 | + message_length_limit: int |
| 22 | + allowed_prefixes: list[str] |
| 23 | + message: str |
| 24 | + |
| 25 | + |
16 | 26 | class Check:
|
17 | 27 | """Check if the current commit msg matches the commitizen format."""
|
18 | 28 |
|
19 |
| - def __init__(self, config: BaseConfig, arguments: dict[str, Any]) -> None: |
| 29 | + def __init__(self, config: BaseConfig, arguments: CheckArgs) -> None: |
20 | 30 | """Initial check command.
|
21 | 31 |
|
22 | 32 | Args:
|
23 | 33 | config: The config object required for the command to perform its action
|
24 | 34 | arguments: All the flags provided by the user
|
25 | 35 | cwd: Current work directory
|
26 | 36 | """
|
27 |
| - self.commit_msg_file: str | None = arguments.get("commit_msg_file") |
28 |
| - self.commit_msg: str | None = arguments.get("message") |
29 |
| - self.rev_range: str | None = arguments.get("rev_range") |
30 |
| - self.allow_abort: bool = bool( |
| 37 | + self.commit_msg_file = arguments.get("commit_msg_file") |
| 38 | + self.commit_msg = arguments.get("message") |
| 39 | + self.rev_range = arguments.get("rev_range") |
| 40 | + self.allow_abort = bool( |
31 | 41 | arguments.get("allow_abort", config.settings["allow_abort"])
|
32 | 42 | )
|
33 |
| - self.max_msg_length: int = arguments.get("message_length_limit", 0) |
| 43 | + self.max_msg_length = arguments.get("message_length_limit", 0) |
34 | 44 |
|
35 | 45 | # we need to distinguish between None and [], which is a valid value
|
36 |
| - |
37 | 46 | allowed_prefixes = arguments.get("allowed_prefixes")
|
38 | 47 | self.allowed_prefixes: list[str] = (
|
39 | 48 | allowed_prefixes
|
|
0 commit comments