13
13
from commitizen .git import GitCommit , smart_open
14
14
from commitizen .version_schemes import Increment , Version
15
15
16
- VERSION_TYPES = [ None , PATCH , MINOR , MAJOR ]
16
+ _INCREMENT_TYPES = ( None , PATCH , MINOR , MAJOR )
17
17
18
18
logger = getLogger ("commitizen" )
19
19
@@ -27,37 +27,42 @@ def find_increment(
27
27
# Most important cases are major and minor.
28
28
# Everything else will be considered patch.
29
29
select_pattern = re .compile (regex )
30
- increment : str | None = None
30
+ increment : Increment | None = None
31
31
32
32
for commit in commits :
33
33
for message in commit .message .split ("\n " ):
34
- if result := select_pattern .search (message ):
35
- found_keyword = result .group (1 )
36
-
37
- new_increment = next (
38
- (
39
- increment_type
40
- for match_pattern , increment_type in increments_map .items ()
41
- if re .match (match_pattern , found_keyword )
42
- ),
43
- None ,
34
+ if not (result := select_pattern .search (message )):
35
+ continue
36
+
37
+ found_keyword = result .group (1 )
38
+ new_increment : Increment | None = next (
39
+ (
40
+ cast (Increment , increment_type )
41
+ for match_pattern , increment_type in increments_map .items ()
42
+ if re .match (match_pattern , found_keyword )
43
+ ),
44
+ None ,
45
+ )
46
+
47
+ if new_increment is None :
48
+ logger .debug (
49
+ f"no increment needed for '{ found_keyword } ' in '{ message } '"
44
50
)
45
51
46
- if new_increment is None :
47
- logger . debug (
48
- f"no increment needed for ' { found_keyword } ' in ' { message } '"
49
- )
52
+ if _INCREMENT_TYPES . index ( increment ) >= _INCREMENT_TYPES . index (
53
+ new_increment
54
+ ):
55
+ continue
50
56
51
- if VERSION_TYPES . index ( increment ) < VERSION_TYPES . index ( new_increment ):
52
- logger . debug (
53
- f"increment detected is ' { new_increment } ' due to ' { found_keyword } ' in ' { message } '"
54
- )
55
- increment = new_increment
57
+ logger . debug (
58
+ f"increment detected is ' { new_increment } ' due to ' { found_keyword } ' in ' { message } '"
59
+ )
60
+ if new_increment == MAJOR :
61
+ return new_increment
56
62
57
- if increment == MAJOR :
58
- break
63
+ increment = new_increment
59
64
60
- return cast ( Increment , increment )
65
+ return increment
61
66
62
67
63
68
def update_version_in_files (
0 commit comments