1313from commitizen .git import GitCommit , smart_open
1414from commitizen .version_schemes import Increment , Version
1515
16- VERSION_TYPES = [ None , PATCH , MINOR , MAJOR ]
16+ _INCREMENT_TYPES = ( None , PATCH , MINOR , MAJOR )
1717
1818logger = getLogger ("commitizen" )
1919
@@ -27,37 +27,42 @@ def find_increment(
2727 # Most important cases are major and minor.
2828 # Everything else will be considered patch.
2929 select_pattern = re .compile (regex )
30- increment : str | None = None
30+ increment : Increment | None = None
3131
3232 for commit in commits :
3333 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 } '"
4450 )
4551
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
5056
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
5662
57- if increment == MAJOR :
58- break
63+ increment = new_increment
5964
60- return cast ( Increment , increment )
65+ return increment
6166
6267
6368def update_version_in_files (
0 commit comments