Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug when there's changed files, but none have missing cov lines #105

Merged
merged 1 commit into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions services/notification/notifiers/mixins/message/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,6 @@
if files_in_diff:
table_header = get_table_header(hide_project_coverage, self.show_complexity)
table_layout = get_table_layout(hide_project_coverage, self.show_complexity)
# add table headers
yield (
"| [Files]({0}?src=pr&el=tree) {1}".format(links["pull"], table_header)
)
yield (table_layout)

# get limit of results to show
limit = int(self.layout.split(":")[1] if ":" in self.layout else 10)
Expand All @@ -514,6 +509,12 @@
)

if not hide_project_coverage:
yield (
"| [Files]({0}?src=pr&el=tree) {1}".format(
links["pull"], table_header
)
)
yield (table_layout)
for line in starmap(
tree_cell,
sorted(files_in_diff, key=lambda a: a[3] or Decimal("0"))[:limit],
Expand All @@ -533,16 +534,22 @@
changed_files = sorted(
files_in_diff, key=lambda a: a[3] or Decimal("0"), reverse=True
)
for file in changed_files:
# misses + partials != 0
if file[3] != 0:
if printed_files == limit:
remaining_files += 1
else:
printed_files += 1
yield (tree_cell(file[0], file[1], file[2]))
changed_files_with_missing_lines = [
f for f in changed_files if f[3] > 0
]
if changed_files_with_missing_lines:
yield (
"| [Files]({0}?src=pr&el=tree) {1}".format(
links["pull"], table_header
)
)
yield (table_layout)
for file in changed_files_with_missing_lines:
if printed_files == limit:
remaining_files += 1

Check warning on line 549 in services/notification/notifiers/mixins/message/sections.py

View check run for this annotation

Codecov - Staging / codecov/patch

services/notification/notifiers/mixins/message/sections.py#L549

Added line #L549 was not covered by tests

Check warning on line 549 in services/notification/notifiers/mixins/message/sections.py

View check run for this annotation

Codecov Public QA / codecov/patch

services/notification/notifiers/mixins/message/sections.py#L549

Added line #L549 was not covered by tests

Check warning on line 549 in services/notification/notifiers/mixins/message/sections.py

View check run for this annotation

Codecov / codecov/patch

services/notification/notifiers/mixins/message/sections.py#L549

Added line #L549 was not covered by tests
else:
break
printed_files += 1
yield (tree_cell(file[0], file[1], file[2]))

if remaining_files:
yield (
Expand Down
79 changes: 79 additions & 0 deletions services/notification/notifiers/tests/unit/test_comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3568,6 +3568,85 @@ async def test_filesection_hide_project_cov(self, sample_comparison, mocker):
"| [file\\_1.go](pull.link?src=pr&el=tree#diff-ZmlsZV8xLmdv) | 66.66% | [1 Missing :warning: ](pull.link?src=pr&el=tree) |",
]

@pytest.mark.asyncio
async def test_filesection_hide_project_cov_with_changed_files_but_no_missing_lines(
self, sample_comparison, mocker
):
section_writer = FileSectionWriter(
sample_comparison.head.commit.repository,
"layout",
show_complexity=False,
settings={"hide_project_coverage": True},
current_yaml={},
)
changes = [
Change(
path="unrelated.py",
in_diff=False,
totals=ReportTotals(
files=0,
lines=0,
hits=-3,
misses=2,
partials=0,
coverage=-43.333330000000004,
branches=0,
methods=0,
messages=0,
sessions=0,
complexity=0,
complexity_total=0,
diff=0,
),
),
Change(path="added.py", new=True, in_diff=None, old_path=None, totals=None),
]
lines = list(
await section_writer.write_section(
sample_comparison,
{
"files": {
"file_1.go": {
"type": "added",
"totals": ReportTotals(
lines=3,
hits=3,
misses=0,
coverage=100.00,
branches=0,
methods=0,
messages=0,
sessions=0,
complexity=0,
complexity_total=0,
diff=0,
),
},
"file_2.py": {
"type": "added",
"totals": ReportTotals(
lines=3,
hits=3,
misses=0,
partials=0,
coverage=-100.00,
branches=0,
methods=0,
messages=0,
sessions=0,
complexity=0,
complexity_total=0,
diff=0,
),
},
}
},
changes,
links={"pull": "pull.link"},
)
)
assert lines == []

@pytest.mark.asyncio
async def test_filesection_hide_project_cov_no_files_changed(
self, sample_comparison, mocker
Expand Down