diff --git a/action.yml b/action.yml
index 37cd8f1..6ec6335 100644
--- a/action.yml
+++ b/action.yml
@@ -100,6 +100,12 @@ inputs:
required: false
default: 'true'
+ # Comment customization
+ title:
+ description: 'Optional heading displayed at the top of the PR comment (e.g. app name in a monorepo).'
+ required: false
+ default: ''
+
# GitHub integration
github-token:
description: 'GitHub token for PR comments and check annotations. Defaults to the built-in GITHUB_TOKEN.'
@@ -204,6 +210,7 @@ runs:
INPUT_CONFIG-FILE: ${{ inputs.config-file }}
INPUT_FAIL-UNDER: ${{ inputs.fail-under }}
INPUT_FAIL-ON-THRESHOLD: ${{ inputs.fail-on-threshold }}
+ INPUT_TITLE: ${{ inputs.title }}
INPUT_GITHUB-TOKEN: ${{ inputs.github-token || github.token }}
INPUT_POST-COMMENT: ${{ inputs.post-comment }}
INPUT_COMMENT-IDENTIFIER: ${{ inputs.comment-identifier }}
diff --git a/entrypoint.py b/entrypoint.py
index ca969e8..ac1a787 100644
--- a/entrypoint.py
+++ b/entrypoint.py
@@ -123,6 +123,7 @@ def main() -> int:
fail_under=fail_under,
threshold_met=threshold_met,
identifier=get_input("comment-identifier", "diff-cover-action"),
+ title=get_input("title"),
md_report_path=md_report_path,
)
print("::endgroup::")
diff --git a/src/comment.py b/src/comment.py
index 642203a..b3c70f5 100644
--- a/src/comment.py
+++ b/src/comment.py
@@ -138,6 +138,7 @@ def _render_comment_body(
fail_under: float,
threshold_met: bool,
identifier: str,
+ title: str,
md_report_content: str,
) -> str:
"""Render the PR comment body from a Jinja2 template."""
@@ -159,6 +160,7 @@ def _render_comment_body(
fail_under=fail_under,
threshold_met=threshold_met,
identifier=identifier,
+ title=title,
md_report_content=md_report_content,
)
@@ -176,6 +178,7 @@ def post_or_update_comment(
fail_under: float,
threshold_met: bool,
identifier: str,
+ title: str = "",
md_report_path: str,
) -> str:
"""Post a new PR comment or update an existing one. Returns the comment ID as a string."""
@@ -202,6 +205,7 @@ def post_or_update_comment(
fail_under=fail_under,
threshold_met=threshold_met,
identifier=identifier,
+ title=title,
md_report_content=md_report_content,
)
diff --git a/templates/comment_coverage.md.j2 b/templates/comment_coverage.md.j2
index 98d618d..4b9783c 100644
--- a/templates/comment_coverage.md.j2
+++ b/templates/comment_coverage.md.j2
@@ -1,4 +1,8 @@
+{% if title %}
+## {{ title }}
+
+{% endif %}
{% set pct = "%.1f" | format(report.total_percent_covered) %}
{% set color = report.total_percent_covered | badge_color %}
diff --git a/templates/comment_quality.md.j2 b/templates/comment_quality.md.j2
index db12d32..d11faea 100644
--- a/templates/comment_quality.md.j2
+++ b/templates/comment_quality.md.j2
@@ -1,4 +1,8 @@
+{% if title %}
+## {{ title }}
+
+{% endif %}
{% set pct = "%.1f" | format(report.total_percent_covered) %}
{% set color = report.total_percent_covered | badge_color %}
|
diff --git a/tests/test_comment.py b/tests/test_comment.py
index 63758e5..4c8ffa0 100644
--- a/tests/test_comment.py
+++ b/tests/test_comment.py
@@ -91,6 +91,7 @@ def test_render_comment_body() -> None:
fail_under=80.0,
threshold_met=True,
identifier="test-id",
+ title="",
md_report_content="",
)
assert "" in body
@@ -99,6 +100,27 @@ def test_render_comment_body() -> None:
assert "src/foo.py" in body
+def test_render_comment_body_with_title() -> None:
+ report = Report(
+ report_name="XML",
+ diff_name="",
+ files=[],
+ total_num_lines=10,
+ total_num_violations=0,
+ total_percent_covered=100.0,
+ )
+ body = _render_comment_body(
+ report=report,
+ mode="coverage",
+ fail_under=80.0,
+ threshold_met=True,
+ identifier="test-id",
+ title="partners-app",
+ md_report_content="",
+ )
+ assert "## partners-app" in body
+
+
def test_render_comment_body_below_threshold() -> None:
report = Report(
report_name="XML",
@@ -114,6 +136,7 @@ def test_render_comment_body_below_threshold() -> None:
fail_under=80.0,
threshold_met=False,
identifier="test",
+ title="",
md_report_content="",
)
assert "threshold-failed-critical" in body
|
|