32
32
from collections .abc import Generator , Iterable , Mapping , Sequence
33
33
from dataclasses import dataclass
34
34
from datetime import date
35
+ from itertools import chain
35
36
from typing import TYPE_CHECKING , Any
36
37
37
38
from jinja2 import (
@@ -88,33 +89,32 @@ def generate_tree_from_commits(
88
89
pat = re .compile (changelog_pattern )
89
90
map_pat = re .compile (commit_parser , re .MULTILINE )
90
91
body_map_pat = re .compile (commit_parser , re .MULTILINE | re .DOTALL )
91
- current_tag : GitTag | None = None
92
92
rules = rules or TagRules ()
93
93
94
94
# 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 ()
103
- if current_tag is not None and current_tag .name :
104
- current_tag_name = current_tag .name
105
- current_tag_date = current_tag .date
106
95
96
+ current_tag = get_commit_tag (commits [0 ], tags ) if commits else None
97
+ current_tag_name = unreleased_version or "Unreleased"
98
+ current_tag_date = (
99
+ date .today ().isoformat () if unreleased_version is not None else ""
100
+ )
101
+
102
+ used_tags : set [GitTag ] = set ()
103
+ if current_tag :
104
+ used_tags .add (current_tag )
105
+ if current_tag .name :
106
+ current_tag_name = current_tag .name
107
+ current_tag_date = current_tag .date
108
+
109
+ commit_tag : GitTag | None = None
107
110
changes : dict = defaultdict (list )
108
- used_tags : list = [current_tag ]
109
111
for commit in commits :
110
- commit_tag = get_commit_tag (commit , tags )
111
-
112
112
if (
113
- commit_tag
113
+ ( commit_tag := get_commit_tag ( commit , tags ))
114
114
and commit_tag not in used_tags
115
115
and rules .include_in_changelog (commit_tag )
116
116
):
117
- used_tags .append (commit_tag )
117
+ used_tags .add (commit_tag )
118
118
release = {
119
119
"version" : current_tag_name ,
120
120
"date" : current_tag_date ,
@@ -127,24 +127,15 @@ def generate_tree_from_commits(
127
127
current_tag_date = commit_tag .date
128
128
changes = defaultdict (list )
129
129
130
- matches = pat .match (commit .message )
131
- if not matches :
130
+ if not pat .match (commit .message ):
132
131
continue
133
132
134
- # Process subject from commit message
135
- if message := map_pat .match (commit .message ):
136
- process_commit_message (
137
- changelog_message_builder_hook ,
138
- message ,
139
- commit ,
140
- changes ,
141
- change_type_map ,
142
- )
143
-
144
- # Process body from commit message
145
- body_parts = commit .body .split ("\n \n " )
146
- for body_part in body_parts :
147
- if message := body_map_pat .match (body_part ):
133
+ # Process subject and body from commit message
134
+ for message in chain (
135
+ [map_pat .match (commit .message )],
136
+ (body_map_pat .match (block ) for block in commit .body .split ("\n \n " )),
137
+ ):
138
+ if message :
148
139
process_commit_message (
149
140
changelog_message_builder_hook ,
150
141
message ,
0 commit comments