- Fix changelog parsing

This commit is contained in:
Nate Harris 2023-10-02 23:01:47 -06:00
commit dfd4527152

View file

@ -30,24 +30,44 @@ def reformat(item_format: str, output_emoji: bool) -> None:
sections = [] sections = []
skip = False
section: Union[SectionType, Dict] = {} section: Union[SectionType, Dict] = {}
for line in data: for line in data:
# If the line is not a list item or a header, skip it
if not line[0] in ["#", "*", "-", "+"]:
continue
# Skip big header
if line.startswith("## "): if line.startswith("## "):
pass skip = True
continue
# Beginning of new section
if line.startswith("### "): if line.startswith("### "):
skip = False
# Save the previous section
if section: if section:
sections.append(section) sections.append(section)
_section: SectionType = {
# Start a new section
section: SectionType = {
"title": line.strip("# "), "title": line.strip("# "),
"items": [], "items": [],
} }
section = _section continue
m = ITEM_PATTERN.match(line) # If skip is enabled, skip the line
if m: if skip:
gd = m.groupdict() continue
# Line is a list item in the current section
item_pattern_match = ITEM_PATTERN.match(line)
if item_pattern_match:
gd = item_pattern_match.groupdict()
section["items"].append(gd) section["items"].append(gd)
continue
# Save the last section
sections.append(section) sections.append(section)
first = True first = True