Skip to content
Merged
Changes from 2 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
45 changes: 34 additions & 11 deletions pr_split/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,28 +260,51 @@ def _create_branches_and_commits(
_gh_semaphore = Semaphore(_GH_API_CONCURRENCY)


def _build_pr_body(group: Group, all_groups: list[Group]) -> str:
sections = [group.description]
_PR_TEMPLATE_PATH = Path(PLAN_DIR) / "template.md"


def _build_pr_body(group: Group, all_groups: list[Group]) -> str:
files = [a.file_path for a in group.assignments]
file_list = "\n".join(f"- `{f}`" for f in files)
dep_list = ", ".join(f"`{d}`" for d in group.depends_on)
dag_md = _render_dag_markdown(all_groups, group.id)

template_vars = {
"description": group.description,
"files": file_list,
"added": group.estimated_added,
"removed": group.estimated_removed,
"loc": group.estimated_loc,
"dependencies": dep_list,
"dag": dag_md,
"id": group.id,
"title": group.title,
}

if _PR_TEMPLATE_PATH.exists():
template = _PR_TEMPLATE_PATH.read_text(encoding="utf-8")
try:
return template.format(**template_vars)
except (KeyError, ValueError) as exc:
available = ", ".join(f"{{{k}}}" for k in sorted(template_vars))
raise PRSplitError(
f"Invalid PR template at {_PR_TEMPLATE_PATH}: {exc}. "
f"Available placeholders: {available}. "
"Escape literal braces with {{ and }}."
) from exc

sections = [group.description]
if files:
file_list = "\n".join(f"- `{f}`" for f in files)
sections.append(f"## Files changed\n\n{file_list}")

sections.append(
f"## Diff stats\n\n"
f"**+{group.estimated_added}** additions, "
f"**-{group.estimated_removed}** deletions "
f"({group.estimated_loc} LOC)"
)

deps = group.depends_on
if deps:
dep_list = ", ".join(f"`{d}`" for d in deps)
if group.depends_on:
sections.append(f"## Dependencies\n\nThis PR depends on: {dep_list}")

sections.append(_render_dag_markdown(all_groups, group.id))

sections.append(dag_md)
return "\n\n".join(sections)


Expand Down
Loading