Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions src/stack_pr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,10 @@ def create_pr(e: StackEntry, *, is_draft: bool, reviewer: str = "") -> None:


def generate_toc(st: list[StackEntry], current: str) -> str:
# Don't generate TOC for single PR
if len(st) == 1:
return ""

def toc_entry(se: StackEntry) -> str:
pr_id = last(se.pr)
arrow = "__->__" if pr_id == current else ""
Expand Down Expand Up @@ -791,23 +795,22 @@ def add_cross_links(st: list[StackEntry], *, keep_body: bool, verbose: bool) ->

# Strip stack-info from the body, nothing interesting there.
body = RE_STACK_INFO_LINE.sub("", body)
pr_body = [
f"{pr_toc}",
f"{CROSS_LINKS_DELIMETER}\n",
]

# Build PR body components
header = []
body_content = body

if pr_toc:
# Multi-PR stack: add TOC header and format body with title
header = [pr_toc, f"{CROSS_LINKS_DELIMETER}\n"]
body_content = f"### {title}\n\n{body}"

if keep_body:
# Keep current body of the PR after the cross links component
current_pr_body = get_current_pr_body(e)
pr_body.append(current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip())
else:
pr_body.extend(
[
f"### {title}",
"",
f"{body}",
]
)
body_content = current_pr_body.split(CROSS_LINKS_DELIMETER, 1)[-1].lstrip()

pr_body = [*header, body_content]

if e.has_base():
run_shell_command(
Expand Down
Loading