12
12
class VersionIncrement (IntEnum ):
13
13
"""An enumeration representing semantic versioning increments.
14
14
15
- This class defines the three types of version increments according to semantic versioning:
15
+ This class defines the four types of version increments according to semantic versioning:
16
+ - NONE: For commits that don't require a version bump (docs, style, etc.)
16
17
- PATCH: For backwards-compatible bug fixes
17
18
- MINOR: For backwards-compatible functionality additions
18
19
- MAJOR: For incompatible API changes
19
20
"""
20
21
22
+ NONE = auto ()
21
23
PATCH = auto ()
22
24
MINOR = auto ()
23
25
MAJOR = auto ()
@@ -26,16 +28,16 @@ def __str__(self) -> str:
26
28
return self .name
27
29
28
30
@classmethod
29
- def safe_cast (cls , value : object ) -> VersionIncrement | None :
31
+ def safe_cast (cls , value : object ) -> VersionIncrement :
30
32
if not isinstance (value , str ):
31
- return None
33
+ return VersionIncrement . NONE
32
34
try :
33
35
return cls [value ]
34
36
except KeyError :
35
- return None
37
+ return VersionIncrement . NONE
36
38
37
- @classmethod
38
- def safe_cast_dict (cls , d : Mapping [str , object ]) -> dict [str , VersionIncrement ]:
39
+ @staticmethod
40
+ def safe_cast_dict (d : Mapping [str , object ]) -> dict [str , VersionIncrement ]:
39
41
return {
40
42
k : v
41
43
for k , v in ((k , VersionIncrement .safe_cast (v )) for k , v in d .items ())
@@ -45,8 +47,8 @@ def safe_cast_dict(cls, d: Mapping[str, object]) -> dict[str, VersionIncrement]:
45
47
@staticmethod
46
48
def get_highest_by_messages (
47
49
commit_messages : Iterable [str ],
48
- extract_increment : Callable [[str ], VersionIncrement | None ],
49
- ) -> VersionIncrement | None :
50
+ extract_increment : Callable [[str ], VersionIncrement ],
51
+ ) -> VersionIncrement :
50
52
"""Find the highest version increment from a list of messages.
51
53
52
54
This function processes a list of messages and determines the highest version
@@ -76,9 +78,9 @@ def get_highest_by_messages(
76
78
77
79
@staticmethod
78
80
def get_highest (
79
- increments : Iterable [VersionIncrement | None ],
80
- ) -> VersionIncrement | None :
81
- return max (filter ( None , increments ) , default = None )
81
+ increments : Iterable [VersionIncrement ],
82
+ ) -> VersionIncrement :
83
+ return max (increments , default = VersionIncrement . NONE )
82
84
83
85
84
86
class BumpRule (Protocol ):
@@ -94,7 +96,7 @@ class BumpRule(Protocol):
94
96
95
97
def extract_increment (
96
98
self , commit_message : str , major_version_zero : bool
97
- ) -> VersionIncrement | None :
99
+ ) -> VersionIncrement :
98
100
"""Determine the version increment based on a commit message.
99
101
100
102
This method analyzes a commit message to determine what kind of version increment
@@ -107,24 +109,24 @@ def extract_increment(
107
109
instead of MAJOR. This is useful for projects in 0.x.x versions.
108
110
109
111
Returns:
110
- VersionIncrement | None: The type of version increment needed:
112
+ VersionIncrement: The type of version increment needed:
113
+ - NONE: For commits that don't require a version bump (docs, style, etc.)
111
114
- MAJOR: For breaking changes when major_version_zero is False
112
115
- MINOR: For breaking changes when major_version_zero is True, or for new features
113
116
- PATCH: For bug fixes, performance improvements, or refactors
114
- - None: For commits that don't require a version bump (docs, style, etc.)
115
117
"""
116
118
117
119
118
120
class ConventionalCommitBumpRule (BumpRule ):
119
- _BREAKING_CHANGE_TYPES = set ([ "BREAKING CHANGE" , "BREAKING-CHANGE" ])
120
- _MINOR_CHANGE_TYPES = set ([ "feat" ])
121
- _PATCH_CHANGE_TYPES = set ([ "fix" , "perf" , "refactor" ])
121
+ _BREAKING_CHANGE_TYPES = { "BREAKING CHANGE" , "BREAKING-CHANGE" }
122
+ _MINOR_CHANGE_TYPES = { "feat" }
123
+ _PATCH_CHANGE_TYPES = { "fix" , "perf" , "refactor" }
122
124
123
125
def extract_increment (
124
126
self , commit_message : str , major_version_zero : bool
125
- ) -> VersionIncrement | None :
127
+ ) -> VersionIncrement :
126
128
if not (m := self ._head_pattern .match (commit_message )):
127
- return None
129
+ return VersionIncrement . NONE
128
130
129
131
change_type = m .group ("change_type" )
130
132
if m .group ("bang" ) or change_type in self ._BREAKING_CHANGE_TYPES :
@@ -138,7 +140,7 @@ def extract_increment(
138
140
if change_type in self ._PATCH_CHANGE_TYPES :
139
141
return VersionIncrement .PATCH
140
142
141
- return None
143
+ return VersionIncrement . NONE
142
144
143
145
@cached_property
144
146
def _head_pattern (self ) -> re .Pattern :
@@ -225,9 +227,9 @@ def __init__(
225
227
226
228
def extract_increment (
227
229
self , commit_message : str , major_version_zero : bool
228
- ) -> VersionIncrement | None :
230
+ ) -> VersionIncrement :
229
231
if not (m := self .bump_pattern .search (commit_message )):
230
- return None
232
+ return VersionIncrement . NONE
231
233
232
234
effective_bump_map = (
233
235
self .bump_map_major_version_zero if major_version_zero else self .bump_map
@@ -250,4 +252,4 @@ def extract_increment(
250
252
for match_pattern , increment in effective_bump_map .items ():
251
253
if re .match (match_pattern , found_keyword ):
252
254
return increment
253
- return None
255
+ return VersionIncrement . NONE
0 commit comments