diff --git a/services/notification/notifiers/mixins/message/sections.py b/services/notification/notifiers/mixins/message/sections.py index 22ffde27f..4754c8203 100644 --- a/services/notification/notifiers/mixins/message/sections.py +++ b/services/notification/notifiers/mixins/message/sections.py @@ -80,20 +80,29 @@ async def write_section(*args, **kwargs): class NewFooterSectionWriter(BaseSectionWriter): async def do_write_section(self, comparison, diff, changes, links, behind_by=None): - repo_service = comparison.repository_service.service - yield ("") - yield ( - "[:umbrella: View full report in Codecov by Sentry]({0}?src=pr&el=continue). ".format( - links["pull"] + hide_project_coverage = self.settings.get("hide_project_coverage", False) + if hide_project_coverage: + yield ("") + yield ( + ":loudspeaker: Thoughts on this report? [Let us know!]({0}).".format( + "https://about.codecov.io/pull-request-comment-report/" + ) ) - ) - yield ( - ":loudspeaker: Have feedback on the report? [Share it here]({0}).".format( - "https://about.codecov.io/codecov-pr-comment-feedback/" - if repo_service == "github" - else "https://gitlab.com/codecov-open-source/codecov-user-feedback/-/issues/4" + else: + repo_service = comparison.repository_service.service + yield ("") + yield ( + "[:umbrella: View full report in Codecov by Sentry]({0}?src=pr&el=continue). ".format( + links["pull"] + ) + ) + yield ( + ":loudspeaker: Have feedback on the report? [Share it here]({0}).".format( + "https://about.codecov.io/codecov-pr-comment-feedback/" + if repo_service == "github" + else "https://gitlab.com/codecov-open-source/codecov-user-feedback/-/issues/4" + ) ) - ) class NewHeaderSectionWriter(BaseSectionWriter): diff --git a/services/notification/notifiers/tests/unit/test_comment.py b/services/notification/notifiers/tests/unit/test_comment.py index d95618a81..104aca9f5 100644 --- a/services/notification/notifiers/tests/unit/test_comment.py +++ b/services/notification/notifiers/tests/unit/test_comment.py @@ -3778,8 +3778,8 @@ async def test_footer_section_writer_in_github(self, mocker): mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock(), - mocker.MagicMock(), - mocker.MagicMock(), + settings={}, + current_yaml=mocker.MagicMock(), ) mock_comparison = mocker.MagicMock() mock_comparison.repository_service.service = "github" @@ -3800,8 +3800,8 @@ async def test_footer_section_writer_in_gitlab(self, mocker): mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock(), - mocker.MagicMock(), - mocker.MagicMock(), + settings={}, + current_yaml=mocker.MagicMock(), ) mock_comparison = mocker.MagicMock() mock_comparison.repository_service.service = "gitlab" @@ -3822,8 +3822,8 @@ async def test_footer_section_writer_in_bitbucket(self, mocker): mocker.MagicMock(), mocker.MagicMock(), mocker.MagicMock(), - mocker.MagicMock(), - mocker.MagicMock(), + settings={}, + current_yaml=mocker.MagicMock(), ) mock_comparison = mocker.MagicMock() mock_comparison.repository_service.service = "bitbucket" @@ -3838,6 +3838,30 @@ async def test_footer_section_writer_in_bitbucket(self, mocker): ":loudspeaker: Have feedback on the report? [Share it here](https://gitlab.com/codecov-open-source/codecov-user-feedback/-/issues/4).", ] + @pytest.mark.asyncio + async def test_footer_section_writer_with_project_cov_hidden(self, mocker): + writer = NewFooterSectionWriter( + mocker.MagicMock(), + mocker.MagicMock(), + mocker.MagicMock(), + settings={ + "layout": "newheader, files, newfooter", + "hide_project_coverage": True, + }, + current_yaml={}, + ) + mock_comparison = mocker.MagicMock() + mock_comparison.repository_service.service = "bitbucket" + res = list( + await writer.write_section( + mock_comparison, {}, [], links={"pull": "pull.link"} + ) + ) + assert res == [ + "", + ":loudspeaker: Thoughts on this report? [Let us know!](https://about.codecov.io/pull-request-comment-report/).", + ] + class TestCommentNotifierInNewLayout(object): @pytest.mark.asyncio @@ -4168,8 +4192,7 @@ async def test_build_message_no_project_coverage( f"| [file\\_1.go](test.example.br/gh/{repository.slug}/pull/{pull.pullid}?src=pr&el=tree#diff-ZmlsZV8xLmdv) | `66.67%` |", f"", f"", - f"[:umbrella: View full report in Codecov by Sentry](test.example.br/gh/{repository.slug}/pull/{pull.pullid}?src=pr&el=continue). ", - f":loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/).", + f":loudspeaker: Thoughts on this report? [Let us know!](https://about.codecov.io/pull-request-comment-report/).", f"", ] for exp, res in zip(expected_result, result):