diff --git a/coverage_comment/main.py b/coverage_comment/main.py index afb5687a..bebfa072 100644 --- a/coverage_comment/main.py +++ b/coverage_comment/main.py @@ -133,6 +133,7 @@ def generate_comment( previous_coverage_rate=previous_coverage, base_template=template.read_template_file("comment.md.j2"), custom_template=config.COMMENT_TEMPLATE, + subproject_id=config.SUBPROJECT_ID, marker=template.get_marker(marker_id=config.SUBPROJECT_ID), ) except template.MissingMarker: diff --git a/coverage_comment/template.py b/coverage_comment/template.py index 9d206f8a..c04833f7 100644 --- a/coverage_comment/template.py +++ b/coverage_comment/template.py @@ -51,6 +51,7 @@ def get_comment_markdown( previous_coverage_rate: decimal.Decimal | None, base_template: str, marker: str, + subproject_id: str | None = None, custom_template: str | None = None, ): loader = CommentLoader(base_template=base_template, custom_template=custom_template) @@ -62,6 +63,7 @@ def get_comment_markdown( previous_coverage_rate=previous_coverage_rate, coverage=coverage, diff_coverage=diff_coverage, + subproject_id=subproject_id, marker=marker, ) except jinja2.exceptions.TemplateError as exc: diff --git a/coverage_comment/template_files/comment.md.j2 b/coverage_comment/template_files/comment.md.j2 index 95543145..5d7639a2 100644 --- a/coverage_comment/template_files/comment.md.j2 +++ b/coverage_comment/template_files/comment.md.j2 @@ -1,4 +1,4 @@ -{% block title %}## Coverage report{% endblock title %} +{% block title %}## Coverage report{% if subproject_id %} ({{ subproject_id }}){% endif %}{% endblock title %} {% block coverage_evolution -%} {% if previous_coverage_rate -%} {% block coverage_evolution_wording -%} diff --git a/tests/unit/test_template.py b/tests/unit/test_template.py index 2494e3a5..5ffe4f80 100644 --- a/tests/unit/test_template.py +++ b/tests/unit/test_template.py @@ -47,11 +47,12 @@ def test_template(coverage_obj, diff_coverage_obj): previous_coverage_rate=decimal.Decimal("0.92"), base_template=template.read_template_file("comment.md.j2"), marker="", + subproject_id="foo", custom_template="""{% extends "base" %} {% block emoji_coverage_down %}:sob:{% endblock emoji_coverage_down %} """, ) - expected = """## Coverage report + expected = """## Coverage report (foo) The coverage rate went from `92%` to `75%` :sob: The branch rate is `50%`. @@ -230,7 +231,7 @@ def test_template__no_branch_no_previous(coverage_obj_no_branch, diff_coverage_o def test_read_template_file(): assert template.read_template_file("comment.md.j2").startswith( - "{% block title %}## Coverage report{% endblock title %}" + "{% block title %}## Coverage report{% if subproject_id %}" )