Skip to content

Commit

Permalink
Add subproject_id in comment
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Aug 5, 2023
1 parent bc2c1e5 commit 049c5b0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions coverage_comment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def generate_comment(
base_template=template.read_template_file("comment.md.j2"),
custom_template=config.COMMENT_TEMPLATE,
marker=marker,
subproject_id=config.SUBPROJECT_ID,
)
except template.MissingMarker:
log.error(
Expand Down
2 changes: 2 additions & 0 deletions coverage_comment/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion coverage_comment/template_files/comment.md.j2
Original file line number Diff line number Diff line change
@@ -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 -%}
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="<!-- foo -->",
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%`.
Expand Down Expand Up @@ -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 %}"
)


Expand Down

0 comments on commit 049c5b0

Please sign in to comment.