Given a list of PRs, check if they have a changelog entry in "Unreleased". If so add the entry to the patch_release section. Don't remove the entry from the unreleased section, just duplicate it.
(
self, version: str, pr_numbers: list[int], date: str = "Insert Date Here"
)
| 406 | self.file.write_text(self.get_text(include_unreleased=include_unreleased)) |
| 407 | |
| 408 | def set_patch_release_notes( |
| 409 | self, version: str, pr_numbers: list[int], date: str = "Insert Date Here" |
| 410 | ) -> None: |
| 411 | """Given a list of PRs, check if they have a changelog entry in |
| 412 | "Unreleased". |
| 413 | |
| 414 | If so add the entry to the patch_release section. Don't remove the entry |
| 415 | from the unreleased section, just duplicate it. |
| 416 | """ |
| 417 | self.patch_release = ChangelogVersion() |
| 418 | self.patch_release.append_lines([f"## Version {version}", "", f"_{date}_", ""]) |
| 419 | backport_subsections = {} |
| 420 | backport_subsubsections = {} |
| 421 | |
| 422 | # Sort by order of appearance then add |
| 423 | changelog_indices = [ |
| 424 | pr_index |
| 425 | for pr_number in pr_numbers |
| 426 | if (pr_index := self.unreleased.pr_index.get(pr_number, None)) |
| 427 | ] |
| 428 | |
| 429 | changelog_indices = sorted( |
| 430 | set(changelog_indices), |
| 431 | key=lambda idx: (idx.subsection, idx.paragraph, idx.entry), |
| 432 | ) |
| 433 | for pr_index in changelog_indices: |
| 434 | subsection = self.unreleased.sections[pr_index.subsection] |
| 435 | if pr_index.subsection in backport_subsections: |
| 436 | backport_subsection = backport_subsections[pr_index.subsection] |
| 437 | else: |
| 438 | backport_subsection = deepcopy(subsection) |
| 439 | backport_subsection.paragraphs = [] |
| 440 | backport_subsections[pr_index.subsection] = backport_subsection |
| 441 | self.patch_release.sections.append(backport_subsection) |
| 442 | |
| 443 | paragraph = subsection.paragraphs[pr_index.paragraph] |
| 444 | subsub_index = (pr_index.subsection, pr_index.paragraph) |
| 445 | if subsub_index in backport_subsubsections: |
| 446 | backport_subsubsection = backport_subsubsections[subsub_index] |
| 447 | else: |
| 448 | backport_subsubsection = deepcopy(paragraph) |
| 449 | backport_subsubsection.entries = [] |
| 450 | backport_subsubsections[subsub_index] = backport_subsubsection |
| 451 | backport_subsection.paragraphs.append(backport_subsubsection) |
| 452 | |
| 453 | entry = paragraph.entries[pr_index.entry] |
| 454 | backport_subsubsection.entries.append(entry) |
| 455 | |
| 456 | def remove_release_notes_from_unreleased_section( |
| 457 | self, pr_numbers: list[int] |