@@ -88,24 +88,21 @@ def generate_tree_from_commits(
8888 pat = re .compile (changelog_pattern )
8989 map_pat = re .compile (commit_parser , re .MULTILINE )
9090 body_map_pat = re .compile (commit_parser , re .MULTILINE | re .DOTALL )
91- current_tag : GitTag | None = None
9291 rules = rules or TagRules ()
9392
9493 # Check if the latest commit is not tagged
95- if commits :
96- latest_commit = commits [0 ]
97- current_tag = get_commit_tag (latest_commit , tags )
98-
99- current_tag_name : str = unreleased_version or "Unreleased"
100- current_tag_date : str = ""
101- if unreleased_version is not None :
102- current_tag_date = date .today ().isoformat ()
94+ current_tag = get_commit_tag (commits [0 ], tags ) if commits else None
95+
96+ current_tag_name = unreleased_version or "Unreleased"
97+ current_tag_date = (
98+ date .today ().isoformat () if unreleased_version is not None else ""
99+ )
103100 if current_tag is not None and current_tag .name :
104101 current_tag_name = current_tag .name
105102 current_tag_date = current_tag .date
106103
107- changes : dict = defaultdict (list )
108- used_tags : list = [current_tag ]
104+ changes : defaultdict [ str | None , list ] = defaultdict (list )
105+ used_tags = [current_tag ]
109106 for commit in commits :
110107 commit_tag = get_commit_tag (commit , tags )
111108
@@ -170,21 +167,23 @@ def process_commit_message(
170167 changes : dict [str | None , list ],
171168 change_type_map : dict [str , str ] | None = None ,
172169):
173- message : dict = {
170+ message = {
174171 "sha1" : commit .rev ,
175172 "parents" : commit .parents ,
176173 "author" : commit .author ,
177174 "author_email" : commit .author_email ,
178175 ** parsed .groupdict (),
179176 }
177+ processed = hook (message , commit ) if hook else message
178+ if not processed :
179+ return
180180
181- if processed := hook (message , commit ) if hook else message :
182- messages = [processed ] if isinstance (processed , dict ) else processed
183- for msg in messages :
184- change_type = msg .pop ("change_type" , None )
185- if change_type_map :
186- change_type = change_type_map .get (change_type , change_type )
187- changes [change_type ].append (msg )
181+ processed_messages = [processed ] if isinstance (processed , dict ) else processed
182+ for msg in processed_messages :
183+ change_type = msg .pop ("change_type" , None )
184+ if change_type_map :
185+ change_type = change_type_map .get (change_type , change_type )
186+ changes [change_type ].append (msg )
188187
189188
190189def order_changelog_tree (tree : Iterable , change_type_order : list [str ]) -> Iterable :
@@ -225,8 +224,7 @@ def render_changelog(
225224 ** kwargs ,
226225) -> str :
227226 jinja_template = get_changelog_template (loader , template )
228- changelog : str = jinja_template .render (tree = tree , ** kwargs )
229- return changelog
227+ return jinja_template .render (tree = tree , ** kwargs )
230228
231229
232230def incremental_build (
@@ -253,7 +251,9 @@ def incremental_build(
253251 for index , line in enumerate (lines ):
254252 if index == unreleased_start :
255253 skip = True
256- elif index == unreleased_end :
254+ continue
255+
256+ if index == unreleased_end :
257257 skip = False
258258 if (
259259 latest_version_position is None
@@ -268,13 +268,15 @@ def incremental_build(
268268
269269 if index == latest_version_position :
270270 output_lines .extend ([new_content , "\n " ])
271-
272271 output_lines .append (line )
273- if not isinstance (latest_version_position , int ):
274- if output_lines and output_lines [- 1 ].strip ():
275- # Ensure at least one blank line between existing and new content.
276- output_lines .append ("\n " )
277- output_lines .append (new_content )
272+
273+ if isinstance (latest_version_position , int ):
274+ return output_lines
275+
276+ if output_lines and output_lines [- 1 ].strip ():
277+ # Ensure at least one blank line between existing and new content.
278+ output_lines .append ("\n " )
279+ output_lines .append (new_content )
278280 return output_lines
279281
280282
@@ -337,17 +339,17 @@ def get_oldest_and_newest_rev(
337339 if not tags_range :
338340 raise NoCommitsFoundError ("Could not find a valid revision range." )
339341
340- oldest_rev : str | None = tags_range [- 1 ].name
342+ oldest_rev = tags_range [- 1 ].name
341343 newest_rev = newest_tag .name
342344
343- # check if it's the first tag created
344- # and it's also being requested as part of the range
345- if oldest_rev == tags [ - 1 ]. name and oldest_rev == oldest_tag_name :
346- return None , newest_rev
347-
348- # when they are the same, and it's also the
349- # first tag created
350- if oldest_rev == newest_rev :
345+ # Return None for oldest_rev if:
346+ # 1. The oldest tag is the last tag in the list and matches the requested oldest tag, or
347+ # 2. The oldest and newest tags are the same
348+ if (
349+ oldest_rev == tags [ - 1 ]. name
350+ and oldest_rev == oldest_tag_name
351+ or oldest_rev == newest_rev
352+ ) :
351353 return None , newest_rev
352354
353355 return oldest_rev , newest_rev
0 commit comments