2
2
3
3
import re
4
4
import sys
5
+ from collections .abc import Generator
5
6
from typing import Any
6
7
7
8
from commitizen import factory , git , out
@@ -32,7 +33,6 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any]) -> None:
32
33
self .max_msg_length : int = arguments .get ("message_length_limit" , 0 )
33
34
34
35
# we need to distinguish between None and [], which is a valid value
35
-
36
36
allowed_prefixes = arguments .get ("allowed_prefixes" )
37
37
self .allowed_prefixes : list [str ] = (
38
38
allowed_prefixes
@@ -46,7 +46,7 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any]) -> None:
46
46
self .encoding = config .settings ["encoding" ]
47
47
self .cz = factory .commiter_factory (self .config )
48
48
49
- def _valid_command_argument (self ):
49
+ def _valid_command_argument (self ) -> None :
50
50
num_exclusive_args_provided = sum (
51
51
arg is not None
52
52
for arg in (self .commit_msg_file , self .commit_msg , self .rev_range )
@@ -59,7 +59,7 @@ def _valid_command_argument(self):
59
59
"See 'cz check -h' for more information"
60
60
)
61
61
62
- def __call__ (self ):
62
+ def __call__ (self ) -> None :
63
63
"""Validate if commit messages follows the conventional pattern.
64
64
65
65
Raises:
@@ -70,12 +70,12 @@ def __call__(self):
70
70
raise NoCommitsFoundError (f"No commit found with range: '{ self .rev_range } '" )
71
71
72
72
pattern = self .cz .schema_pattern ()
73
- ill_formated_commits = [
73
+ ill_formated_commits : Generator [ git . GitCommit ] = (
74
74
commit
75
75
for commit in commits
76
76
if not self .validate_commit_message (commit .message , pattern )
77
- ]
78
- displayed_msgs_content = "\n " .join (
77
+ )
78
+ displayed_msgs_content : str = "\n " .join (
79
79
[
80
80
f'commit "{ commit .rev } ": "{ commit .message } "'
81
81
for commit in ill_formated_commits
@@ -90,7 +90,8 @@ def __call__(self):
90
90
)
91
91
out .success ("Commit validation: successful!" )
92
92
93
- def _get_commits (self ):
93
+ def _get_commits (self ) -> list [git .GitCommit ]:
94
+ # TODO: this method seems to do a few different things. probably would be better if we could split it to smaller functions
94
95
msg = None
95
96
# Get commit message from file (--commit-msg-file)
96
97
if self .commit_msg_file is not None :
0 commit comments