Skip to content

Commit afd99d8

Browse files
committed
Move table layout to template
1 parent 3a9fc53 commit afd99d8

File tree

2 files changed

+34
-37
lines changed

2 files changed

+34
-37
lines changed

repomatic/github/pr_body.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
from importlib.resources import as_file, files
3030
from string import Template
3131

32-
from click_extra import TableFormat, render_table
33-
3432

3533
def _unescape_dollars(text: str) -> str:
3634
r"""Replace ``\$`` with ``$`` in template text.
@@ -142,7 +140,7 @@ def render_template(*names: str, **kwargs: str) -> str:
142140
append_footer = True
143141
result = "\n\n".join(parts)
144142
if append_footer:
145-
result += "\n\n" + generated_footer()
143+
result += "\n\n---\n\n" + render_template("generated-footer")
146144
result = re.sub(r"\n{3,}", "\n\n", result)
147145
if append_footer:
148146
result += "\n"
@@ -250,28 +248,28 @@ def generate_pr_metadata_block() -> str:
250248
workflow_url = (
251249
f"{server_url}/{repository}/blob/{sha}/.github/workflows/{workflow_file}"
252250
)
251+
commit_url = f"{server_url}/{repository}/commit/{sha}"
253252

254-
rows = [
255-
["**Trigger**", f"`{event_name}`"],
256-
["**Actor**", f"@{actor}"],
257-
]
253+
rerun_row = ""
258254
if triggering_actor and triggering_actor != actor:
259-
rows.append(["**Re-run by**", f"@{triggering_actor}"])
260-
rows += [
261-
["**Ref**", f"`{ref_name}`"],
262-
["**Commit**", f"[`{sha[:8]}`]({server_url}/{repository}/commit/{sha})"],
263-
["**Job**", f"`{job}`"],
264-
["**Workflow**", f"[`{workflow_file}`]({workflow_url})"],
265-
["**Run**", f"[#{run_number}.{run_attempt}]({run_url})"],
266-
]
267-
table = render_table(
268-
rows,
269-
headers=["Field", "Value"],
270-
table_format=TableFormat.GITHUB,
255+
rerun_row = f"| **Re-run by** | @{triggering_actor} |\n"
256+
257+
return render_template(
258+
"pr-metadata",
259+
event_name=event_name,
260+
actor=actor,
261+
rerun_row=rerun_row,
262+
ref_name=ref_name,
263+
sha_short=sha[:8],
264+
commit_url=commit_url,
265+
job=job,
266+
workflow_file=workflow_file,
267+
workflow_url=workflow_url,
268+
run_number=run_number,
269+
run_attempt=run_attempt,
270+
run_url=run_url,
271271
)
272272

273-
return render_template("pr-metadata", table=table)
274-
275273

276274
def _repo_url() -> str:
277275
"""Build repository URL from ``GITHUB_SERVER_URL`` and ``GITHUB_REPOSITORY``."""
@@ -301,23 +299,16 @@ def generate_refresh_tip() -> str:
301299
return render_template("refresh-tip", workflow_dispatch_url=workflow_dispatch_url)
302300

303301

304-
def generated_footer() -> str:
305-
"""Render the attribution footer from the ``generated-footer`` template.
306-
307-
Single source of truth for the attribution line appended to all PR and
308-
issue bodies produced by repomatic.
309-
310-
:return: A markdown string with a horizontal rule and the attribution line.
311-
"""
312-
return "---\n\n" + render_template("generated-footer")
313-
314302

315303
def build_pr_body(prefix: str, metadata_block: str) -> str:
316-
"""Concatenate prefix, refresh tip, metadata block, and footer into a PR body.
304+
"""Concatenate prefix, refresh tip, and metadata block into a PR body.
305+
306+
The ``metadata_block`` already includes the attribution footer (appended
307+
automatically by :func:`render_template`).
317308
318309
:param prefix: Content to prepend before the metadata block. Can be empty.
319310
:param metadata_block: The collapsible metadata block from
320-
:func:`generate_pr_metadata_block`.
311+
:func:`generate_pr_metadata_block`, with footer.
321312
:return: The complete PR body string.
322313
"""
323314
parts: list[str] = []
@@ -327,5 +318,4 @@ def build_pr_body(prefix: str, metadata_block: str) -> str:
327318
if tip:
328319
parts.append(tip)
329320
parts.append(metadata_block)
330-
parts.append(generated_footer())
331321
return "\n\n\n".join(parts)

repomatic/templates/pr-metadata.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
---
2-
args: [table]
3-
footer: false
2+
args: [event_name, actor, rerun_row, ref_name, sha_short, commit_url, job, workflow_file, workflow_url, run_number, run_attempt, run_url]
43
---
54

65
<details><summary><code>Workflow metadata</code></summary>
76

8-
\$table
7+
| Field | Value |
8+
| :-- | :-- |
9+
| **Trigger** | `\$event_name` |
10+
| **Actor** | @\$actor |
11+
\$rerun_row| **Ref** | `\$ref_name` |
12+
| **Commit** | [`\$sha_short`](\$commit_url) |
13+
| **Job** | `\$job` |
14+
| **Workflow** | [`\$workflow_file`](\$workflow_url) |
15+
| **Run** | [#\$run_number.\$run_attempt](\$run_url) |
916

1017
</details>

0 commit comments

Comments
 (0)