Skip to content

Commit

Permalink
Display subproject_id in readme & log
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Aug 10, 2023
1 parent c441292 commit a00d656
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 1 deletion.
3 changes: 3 additions & 0 deletions coverage_comment/communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def get_readme_and_log(
html_report_url: str,
markdown_report: str,
is_public: bool,
subproject_id: str | None = None,
) -> tuple[files.WriteFile, str]:
readme_markdown = template.get_readme_markdown(
is_public=is_public,
Expand All @@ -18,6 +19,7 @@ def get_readme_and_log(
direct_image_url=image_urls["direct"],
endpoint_image_url=image_urls["endpoint"],
dynamic_image_url=image_urls["dynamic"],
subproject_id=subproject_id,
)
log_message = template.get_log_message(
is_public=is_public,
Expand All @@ -26,6 +28,7 @@ def get_readme_and_log(
direct_image_url=image_urls["direct"],
endpoint_image_url=image_urls["endpoint"],
dynamic_image_url=image_urls["dynamic"],
subproject_id=subproject_id,
)
readme = files.WriteFile(
path=pathlib.Path("README.md"),
Expand Down
1 change: 1 addition & 0 deletions coverage_comment/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ def save_coverage_data_files(
image_urls=files.get_urls(url_getter=url_getter),
html_report_url=html_report_url,
markdown_report=markdown_report,
subproject_id=config.SUBPROJECT_ID,
)
operations.append(readme_file)
storage.commit_operations(
Expand Down
4 changes: 4 additions & 0 deletions coverage_comment/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_readme_markdown(
html_report_url: str | None,
dynamic_image_url: str | None,
endpoint_image_url: str | None,
subproject_id: str | None = None,
):
env = SandboxedEnvironment()
template = jinja2.Template(read_template_file("readme.md.j2"))
Expand All @@ -94,6 +95,7 @@ def get_readme_markdown(
html_report_url=html_report_url,
dynamic_image_url=dynamic_image_url,
endpoint_image_url=endpoint_image_url,
subproject_id=subproject_id,
)


Expand All @@ -104,6 +106,7 @@ def get_log_message(
html_report_url: str | None,
dynamic_image_url: str | None,
endpoint_image_url: str | None,
subproject_id: str | None = None,
):
env = SandboxedEnvironment()
template = jinja2.Template(read_template_file("log.txt.j2"))
Expand All @@ -114,6 +117,7 @@ def get_log_message(
endpoint_image_url=endpoint_image_url,
dynamic_image_url=dynamic_image_url,
readme_url=readme_url,
subproject_id=subproject_id,
)


Expand Down
3 changes: 3 additions & 0 deletions coverage_comment/template_files/log.txt.j2
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{% if subproject_id %} Coverage info for {{ subproject_id }}:

{% endif -%}
{% if is_public -%}
You can browse the full coverage report at:
{{ html_report_url }}
Expand Down
2 changes: 1 addition & 1 deletion coverage_comment/template_files/readme.md.j2
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Repository Coverage
# Repository Coverage{% if subproject_id %} ({{ subproject_id }}){% endif %}

{% if is_public -%}
[Full report]({{ html_report_url }})
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,23 @@ def test_get_readme_and_log__public():
assert "https://c" in log


def test_get_readme_and_log__subproject():
readme_file, log = communication.get_readme_and_log(
is_public=True,
image_urls={
"direct": "https://a",
"endpoint": "https://b",
"dynamic": "https://c",
},
readme_url="https://readme",
html_report_url="https://html_report",
markdown_report="**Hello report!**",
subproject_id="my-subproject",
)
assert "Coverage info for my-subproject" in log
assert "# Repository Coverage (my-subproject)" in readme_file.contents


def test_get_readme_and_log__private():
readme_file, log = communication.get_readme_and_log(
is_public=False,
Expand Down

0 comments on commit a00d656

Please sign in to comment.