Skip to content

Commit 50c71a2

Browse files
committed
feature: skip covered files in the report
1 parent 16a147a commit 50c71a2

File tree

6 files changed

+95
-51
lines changed

6 files changed

+95
-51
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Note: Either `GITHUB_PR_NUMBER` or `GITHUB_REF` is required. `GITHUB_PR_NUMBER`
5151
- `ANNOTATE_MISSING_LINES`: Whether to annotate missing lines in the coverage report. Default is False.
5252
- `ANNOTATION_TYPE`: The type of annotation to use for missing lines. 'notice' or 'warning' or 'error'. Default is 'warning'.
5353
- `MAX_FILES_IN_COMMENT`: The maximum number of files to include in the coverage report comment. Default is 25.
54+
- `SKIP_COVERED_FILES_IN_REPORT`: Skip the files with coverage 100% from the report. Default is True.
5455
- `COMPLETE_PROJECT_REPORT`: Whether to include the complete project coverage report in the comment. Default is False.
5556
- `COVERAGE_REPORT_URL`: URL of the full coverage report to mention in the comment.
5657
- `DEBUG`: Whether to enable debug mode. Default is False.

codecov/config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class Config:
5353
ANNOTATIONS_OUTPUT_PATH: pathlib.Path | None = None
5454
ANNOTATIONS_DATA_BRANCH: str | None = None
5555
MAX_FILES_IN_COMMENT: int = 25
56+
SKIP_COVERED_FILES_IN_REPORT: bool = True
5657
COMPLETE_PROJECT_REPORT: bool = False
5758
COVERAGE_REPORT_URL: str | None = None
5859
# Only for debugging, not exposed in the action
@@ -87,6 +88,10 @@ def clean_branch_coverage(cls, value: str) -> bool:
8788
def clean_complete_project_report(cls, value: str) -> bool:
8889
return str_to_bool(value)
8990

91+
@classmethod
92+
def clean_skip_covered_files_in_report(cls, value: str) -> bool:
93+
return str_to_bool(value)
94+
9095
@classmethod
9196
def clean_debug(cls, value: str) -> bool:
9297
return str_to_bool(value)

codecov/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,16 @@ def _process_pr(self):
7171

7272
log.info('Generating comment for PR #%s', self.github.pr_number)
7373
marker = template.get_marker(marker_id=self.config.SUBPROJECT_ID)
74-
files_info, count_files, changed_files_info = template.select_changed_files(
74+
files_info, count_files = template.select_changed_files(
7575
coverage=self.coverage,
7676
diff_coverage=self.diff_coverage,
7777
max_files=self.config.MAX_FILES_IN_COMMENT,
78+
skip_covered_files_in_report=self.config.SKIP_COVERED_FILES_IN_REPORT,
7879
)
7980
coverage_files_info, count_coverage_files = template.select_files(
8081
coverage=self.coverage,
81-
changed_files_info=changed_files_info,
8282
max_files=self.config.MAX_FILES_IN_COMMENT - count_files, # Truncate the report to MAX_FILES_IN_COMMENT
83+
skip_covered_files_in_report=self.config.SKIP_COVERED_FILES_IN_REPORT,
8384
)
8485
try:
8586
comment = template.get_comment_markdown(

codecov/template.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,11 @@ def get_comment_markdown( # pylint: disable=too-many-arguments,too-many-locals
142142

143143

144144
def select_changed_files(
145-
*,
146145
coverage: Coverage,
147146
diff_coverage: DiffCoverage,
148147
max_files: int | None,
149-
) -> tuple[list[FileInfo], int, list[FileInfo]]:
148+
skip_covered_files_in_report: bool,
149+
) -> tuple[list[FileInfo], int]:
150150
"""
151151
Selects the MAX_FILES files with the most new missing lines sorted by path
152152
These are the files which have been modified in the PR
@@ -156,44 +156,42 @@ def select_changed_files(
156156
files = []
157157
for path, coverage_file in coverage.files.items():
158158
diff_coverage_file = diff_coverage.files.get(path)
159+
if not (diff_coverage_file and diff_coverage_file.added_statements):
160+
continue
161+
162+
if skip_covered_files_in_report and percentage_value(diff_coverage_file.percent_covered) == 100:
163+
continue
159164

160165
file_info = FileInfo(
161166
path=path,
162167
coverage=coverage_file,
163168
diff=diff_coverage_file,
164169
)
165-
has_diff = bool(diff_coverage_file and diff_coverage_file.added_statements)
166-
167-
if has_diff:
168-
files.append(file_info)
170+
files.append(file_info)
169171

170-
return sort_and_trucate_files(files=files, max_files=max_files), len(files), files
172+
return sort_and_trucate_files(files=files, max_files=max_files), len(files)
171173

172174

173175
def select_files(
174-
*,
175176
coverage: Coverage,
176-
changed_files_info: list[FileInfo],
177177
max_files: int | None,
178+
skip_covered_files_in_report: bool,
178179
) -> tuple[list[FileInfo], int]:
179180
"""
180181
Selects the no of `max_files` files from the whole project coverage
181-
Selects only files which are not in changed files report
182182
Select only files which have statements (not empty files)
183+
Select only files which have lines missing coverage if `skip_covered_files_in_report` is True
183184
"""
184185

185186
files = []
186-
changed_files_path = {file.path for file in changed_files_info}
187187
for path, coverage_file in coverage.files.items():
188-
# Don't show the report for files that have been modified in the PR
189-
# This is gonne be covered in the changed files report
190-
if path in changed_files_path:
191-
continue
192-
193188
# Don't show the report for files that have no statements
194189
if coverage_file.info.num_statements == 0:
195190
continue
196191

192+
if skip_covered_files_in_report and percentage_value(coverage_file.info.percent_covered) == 100:
193+
continue
194+
197195
file_info = FileInfo(path=path, coverage=coverage_file, diff=None)
198196
files.append(file_info)
199197

tests/test_config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ def test_config_clean_complete_project_report():
149149
assert value is True
150150

151151

152+
def test_config_clean_skip_covered_files_in_report():
153+
value = config.Config.clean_skip_covered_files_in_report('True')
154+
assert value is True
155+
156+
152157
def test_config_clean_debug():
153158
value = config.Config.clean_debug('False')
154159
assert value is False

0 commit comments

Comments
 (0)