Skip to content

Commit 1509316

Browse files
authored
Don't generate table of contents for stacks with just 1 PR. (#103)
To unclutter the view.
1 parent c53c889 commit 1509316

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/stack_pr/cli.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,10 @@ def create_pr(e: StackEntry, *, is_draft: bool, reviewer: str = "") -> None:
753753

754754

755755
def generate_toc(st: list[StackEntry], current: str) -> str:
756+
# Don't generate TOC for single PR
757+
if len(st) == 1:
758+
return ""
759+
756760
def toc_entry(se: StackEntry) -> str:
757761
pr_id = last(se.pr)
758762
arrow = "__->__" if pr_id == current else ""
@@ -782,23 +786,22 @@ def add_cross_links(st: list[StackEntry], *, keep_body: bool, verbose: bool) ->
782786

783787
# Strip stack-info from the body, nothing interesting there.
784788
body = RE_STACK_INFO_LINE.sub("", body)
785-
pr_body = [
786-
f"{pr_toc}",
787-
f"{CROSS_LINKS_DELIMETER}\n",
788-
]
789+
790+
# Build PR body components
791+
header = []
792+
body_content = body
793+
794+
if pr_toc:
795+
# Multi-PR stack: add TOC header and format body with title
796+
header = [pr_toc, f"{CROSS_LINKS_DELIMETER}\n"]
797+
body_content = f"### {title}\n\n{body}"
789798

790799
if keep_body:
791800
# Keep current body of the PR after the cross links component
792801
current_pr_body = get_current_pr_body(e)
793-
pr_body.append(current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip())
794-
else:
795-
pr_body.extend(
796-
[
797-
f"### {title}",
798-
"",
799-
f"{body}",
800-
]
801-
)
802+
body_content = current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip()
803+
804+
pr_body = [*header, body_content]
802805

803806
if e.has_base():
804807
run_shell_command(

0 commit comments

Comments
 (0)