Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand Down Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::")
Expand Down
4 changes: 4 additions & 0 deletions src/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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,
)

Expand All @@ -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."""
Expand All @@ -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,
)

Expand Down
4 changes: 4 additions & 0 deletions templates/comment_coverage.md.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!-- diff-cover-action:{{ identifier }} -->
{% if title %}
## {{ title }}

{% endif %}
{% set pct = "%.1f" | format(report.total_percent_covered) %}
{% set color = report.total_percent_covered | badge_color %}
<table><tr><td>
Expand Down
4 changes: 4 additions & 0 deletions templates/comment_quality.md.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<!-- diff-cover-action:{{ identifier }} -->
{% if title %}
## {{ title }}

{% endif %}
{% set pct = "%.1f" | format(report.total_percent_covered) %}
{% set color = report.total_percent_covered | badge_color %}
<table><tr><td>
Expand Down
23 changes: 23 additions & 0 deletions tests/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<!-- diff-cover-action:test-id -->" in body
Expand All @@ -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",
Expand All @@ -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
Expand Down
Loading