Skip to content

Commit

Permalink
handle new names for the new sections. newheader, newfooter and newfi…
Browse files Browse the repository at this point in the history
…les are now condensed_header, condensed_footer and condensed_files
  • Loading branch information
dana-yaish committed Nov 3, 2023
1 parent 3f5918e commit ec28166
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
28 changes: 24 additions & 4 deletions services/notification/notifiers/mixins/message/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,40 @@ def get_middle_layout_section_names(self, settings):
return [
section
for section in sections
if section not in ["header", "newheader", "newfooter", "newfiles"]
if section
not in [
"header",
"newheader",
"newfooter",
"newfiles",
"condensed_header",
"condensed_footer",
"condensed_files",
]
]

def get_upper_section_names(self, settings):
sections = list(map(lambda l: l.strip(), (settings["layout"] or "").split(",")))
if "newheader" not in sections and "header" not in sections:
headers = ["newheader", "header", "condensed_header"]
if all(not x in sections for x in headers):
sections.insert(0, "header")

return [
section
for section in sections
if section in ["header", "newheader", "newfiles"]
if section
in [
"header",
"newheader",
"condensed_header",
"newfiles",
"condensed_files",
]
]

def get_lower_section_name(self, settings):
if "newfooter" in settings["layout"]:
if (
"newfooter" in settings["layout"]
or "condensed_footer" in settings["layout"]
):
return "newfooter"
6 changes: 3 additions & 3 deletions services/notification/notifiers/mixins/message/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def get_section_class_from_layout_name(layout_name):
return AnnouncementSectionWriter
if layout_name == "header":
return HeaderSectionWriter
if layout_name == "newheader":
if layout_name == "newheader" or layout_name == "condensed_header":
return NewHeaderSectionWriter
if layout_name == "newfooter":
if layout_name == "newfooter" or layout_name == "condensed_footer":
return NewFooterSectionWriter
if layout_name.startswith("component"):
return ComponentsSectionWriter
if layout_name == "newfiles":
if layout_name == "newfiles" or layout_name == "condensed_files":
return NewFilesSectionWriter


Expand Down
41 changes: 41 additions & 0 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4473,6 +4473,47 @@ async def test_build_message_no_project_coverage(
assert exp == res
assert result == expected_result

@pytest.mark.asyncio
async def test_build_message_no_project_coverage_condensed_yaml_configs(
self,
dbsession,
mock_configuration,
mock_repo_provider,
sample_comparison,
):
mock_configuration.params["setup"]["codecov_dashboard_url"] = "test.example.br"
comparison = sample_comparison
comparison.repository_service.service = "github"
pull = comparison.pull
notifier = CommentNotifier(
repository=comparison.head.commit.repository,
title="title",
notifier_yaml_settings={
"layout": "condensed_header, condensed_files, condensed_footer",
"hide_project_coverage": True,
},
notifier_site_settings=True,
current_yaml={},
)
repository = comparison.head.commit.repository
result = await notifier.build_message(comparison)
pull_url = f"test.example.br/gh/{repository.slug}/pull/{pull.pullid}"
expected_result = [
f"## [Codecov]({pull_url}?src=pr&el=h1) Report",
f"Attention: `1 lines` in your changes are missing coverage. Please review.",
f"",
f"| [Files]({pull_url}?src=pr&el=tree) | Patch % | Lines |",
f"|---|---|---|",
f"| [file\\_1.go]({pull_url}?src=pr&el=tree#diff-ZmlsZV8xLmdv) | 66.67% | [1 Missing :warning: ]({pull_url}?src=pr&el=tree) |",
f"",
f"",
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):
assert exp == res
assert result == expected_result

@pytest.mark.asyncio
async def test_build_message_head_and_pull_head_differ_new_layout(
self,
Expand Down

0 comments on commit ec28166

Please sign in to comment.