diff --git a/coverage_comment/communication.py b/coverage_comment/communication.py index 33a5e6fb..bfe38d57 100644 --- a/coverage_comment/communication.py +++ b/coverage_comment/communication.py @@ -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, @@ -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, @@ -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"), diff --git a/coverage_comment/main.py b/coverage_comment/main.py index 0292b78c..93b68d3a 100644 --- a/coverage_comment/main.py +++ b/coverage_comment/main.py @@ -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( diff --git a/coverage_comment/template.py b/coverage_comment/template.py index c04833f7..02f2df80 100644 --- a/coverage_comment/template.py +++ b/coverage_comment/template.py @@ -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")) @@ -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, ) @@ -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")) @@ -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, ) diff --git a/coverage_comment/template_files/log.txt.j2 b/coverage_comment/template_files/log.txt.j2 index 0b69f097..b8d252c2 100644 --- a/coverage_comment/template_files/log.txt.j2 +++ b/coverage_comment/template_files/log.txt.j2 @@ -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 }} diff --git a/coverage_comment/template_files/readme.md.j2 b/coverage_comment/template_files/readme.md.j2 index 8f85075e..e7d7d69e 100644 --- a/coverage_comment/template_files/readme.md.j2 +++ b/coverage_comment/template_files/readme.md.j2 @@ -1,4 +1,4 @@ -# Repository Coverage +# Repository Coverage{% if subproject_id %} ({{ subproject_id }}){% endif %} {% if is_public -%} [Full report]({{ html_report_url }}) diff --git a/tests/unit/test_communication.py b/tests/unit/test_communication.py index 7fdb2b0a..033cdf77 100644 --- a/tests/unit/test_communication.py +++ b/tests/unit/test_communication.py @@ -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,