From 65c067368d15ae697f6c330258dda2d3a1b041e7 Mon Sep 17 00:00:00 2001 From: MUsama Date: Thu, 23 Apr 2026 12:16:54 +0500 Subject: [PATCH 1/2] feat: add title input for PR comment heading Add optional `title` input that renders as an H2 heading at the top of the PR comment. Useful in monorepos where multiple coverage-check jobs run in a matrix and each comment needs to identify which app it belongs to. Usage: - name: Coverage uses: Affanmir/diff-cover-action@v2 with: title: partners-app coverage-files: coverage/lcov.info Co-Authored-By: Claude Opus 4.6 (1M context) --- action.yml | 7 +++++++ entrypoint.py | 1 + src/comment.py | 4 ++++ templates/comment_coverage.md.j2 | 4 ++++ templates/comment_quality.md.j2 | 4 ++++ 5 files changed, 20 insertions(+) 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 %}
From a0a5be45daff84b3b32ff0c44ef7a5d475ddf7ef Mon Sep 17 00:00:00 2001 From: MUsama Date: Sat, 25 Apr 2026 09:54:11 +0500 Subject: [PATCH 2/2] fix: add title param to existing tests and add title rendering test - Add title="" to test_render_comment_body and test_render_comment_body_below_threshold - Add test_render_comment_body_with_title to verify title renders as heading Co-Authored-By: Claude Opus 4.6 (1M context) --- tests/test_comment.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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