Skip to content

Commit ef31a8d

Browse files
committed
Don't generate table of contents for stacks with just 1 PR.
To unclutter the view. stack-info: PR: #103, branch: ZolotukhinM/stack/1
1 parent a4dc185 commit ef31a8d

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
@@ -762,6 +762,10 @@ def create_pr(e: StackEntry, *, is_draft: bool, reviewer: str = "") -> None:
762762

763763

764764
def generate_toc(st: list[StackEntry], current: str) -> str:
765+
# Don't generate TOC for single PR
766+
if len(st) == 1:
767+
return ""
768+
765769
def toc_entry(se: StackEntry) -> str:
766770
pr_id = last(se.pr)
767771
arrow = "__->__" if pr_id == current else ""
@@ -791,23 +795,22 @@ def add_cross_links(st: list[StackEntry], *, keep_body: bool, verbose: bool) ->
791795

792796
# Strip stack-info from the body, nothing interesting there.
793797
body = RE_STACK_INFO_LINE.sub("", body)
794-
pr_body = [
795-
f"{pr_toc}",
796-
f"{CROSS_LINKS_DELIMETER}\n",
797-
]
798+
799+
# Build PR body components
800+
header = []
801+
body_content = body
802+
803+
if pr_toc:
804+
# Multi-PR stack: add TOC header and format body with title
805+
header = [pr_toc, f"{CROSS_LINKS_DELIMETER}\n"]
806+
body_content = f"### {title}\n\n{body}"
798807

799808
if keep_body:
800809
# Keep current body of the PR after the cross links component
801810
current_pr_body = get_current_pr_body(e)
802-
pr_body.append(current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip())
803-
else:
804-
pr_body.extend(
805-
[
806-
f"### {title}",
807-
"",
808-
f"{body}",
809-
]
810-
)
811+
body_content = current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip()
812+
813+
pr_body = [*header, body_content]
811814

812815
if e.has_base():
813816
run_shell_command(

0 commit comments

Comments
 (0)