Skip to content

Commit

Permalink
Merge pull request #105 from codecov/dana/no-missing-lines-bug
Browse files Browse the repository at this point in the history
fix bug when there's changed files, but none have missing cov lines
  • Loading branch information
dana-yaish committed Sep 21, 2023
2 parents 5aff524 + 5645820 commit 21da335
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 14 deletions.
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 @@ async def do_write_section(self, comparison, diff, changes, links, behind_by=Non
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 @@ def tree_cell(typ, path, metrics, _=None):
)

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 @@ def tree_cell(typ, path, metrics, _=None):
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
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

0 comments on commit 21da335

Please sign in to comment.