INNER CODE UNIT · Python
reorder_change_sections
fluxerapp/flutter_client · .github/scripts/append_release_direct_commits.py:251
def reorder_change_sections(body: str) -> str:
extracted_sections: list[tuple[str, str]] = []
for heading in SECTION_ORDER:
section_pattern = re.compile(
rf"\n{re.escape(heading)}\n(.*?)(?=\n### |\Z)",
re.DOTALL,
)
match = section_pattern.search(body)
if match is None:
continue
extracted_sections.append((heading, match.group(1).rstrip()))
body = body[: match.start()] + body[match.end() :]
if len(extracted_sections) == 0:
return body
rebuilt_sections = "".join(f"\n{heading}\n{content}\n" for heading, content in extracted_sections)
detailed_match = re.search(rf"{re.escape(DETAILED_CHANGES_HEADING)}\n", body)
if detailed_match is not None:
insert_at = len(body.rstrip())