3
3
import os
4
4
import re
5
5
import sys
6
+ from itertools import islice
6
7
from typing import Any
7
8
8
9
from commitizen import factory , git , out
@@ -34,7 +35,6 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
34
35
self .max_msg_length : int = arguments .get ("message_length_limit" , 0 )
35
36
36
37
# we need to distinguish between None and [], which is a valid value
37
-
38
38
allowed_prefixes = arguments .get ("allowed_prefixes" )
39
39
self .allowed_prefixes : list [str ] = (
40
40
allowed_prefixes
@@ -44,7 +44,7 @@ def __init__(self, config: BaseConfig, arguments: dict[str, Any], cwd=os.getcwd(
44
44
45
45
self ._valid_command_argument ()
46
46
47
- self .config : BaseConfig = config
47
+ self .config = config
48
48
self .encoding = config .settings ["encoding" ]
49
49
self .cz = factory .committer_factory (self .config )
50
50
@@ -73,11 +73,9 @@ def __call__(self):
73
73
74
74
pattern = self .cz .schema_pattern ()
75
75
displayed_msgs_content = "\n " .join (
76
- [
77
- f'commit "{ commit .rev } ": "{ commit .message } "'
78
- for commit in commits
79
- if not self .validate_commit_message (commit .message , pattern )
80
- ]
76
+ f'commit "{ commit .rev } ": "{ commit .message } "'
77
+ for commit in commits
78
+ if not self .validate_commit_message (commit .message , pattern )
81
79
)
82
80
if displayed_msgs_content :
83
81
raise InvalidCommitMessageError (
@@ -126,14 +124,18 @@ def _filter_comments(msg: str) -> str:
126
124
Returns:
127
125
The filtered commit message without comments.
128
126
"""
129
-
130
- lines = []
131
- for line in msg .split ("\n " ):
132
- if "# ------------------------ >8 ------------------------" in line :
133
- break
134
- if not line .startswith ("#" ):
135
- lines .append (line )
136
- return "\n " .join (lines )
127
+ msg_lines = msg .split ("\n " )
128
+ cutoff = next (
129
+ (
130
+ i
131
+ for i , line in enumerate (msg_lines )
132
+ if "# ------------------------ >8 ------------------------" in line
133
+ ),
134
+ len (msg_lines ),
135
+ )
136
+ return "\n " .join (
137
+ line for line in islice (msg_lines , cutoff ) if not line .startswith ("#" )
138
+ )
137
139
138
140
def validate_commit_message (self , commit_msg : str , pattern : str ) -> bool :
139
141
if not commit_msg :
0 commit comments