Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ Note: Either `GITHUB_PR_NUMBER` or `GITHUB_REF` is required.
- `SUBPROJECT_ID`: The ID or URL of the subproject or report.
- `MINIMUM_GREEN`: The minimum coverage percentage for green status. Default is 100.
- `MINIMUM_ORANGE`: The minimum coverage percentage for orange status. Default is 70.
- `BRANCH_COVERAGE`: Show branch coverage in the report. Default is False.
- `SKIP_COVERAGE`: Skip coverage reporting as github comment and generate only annotaions. Default is False.
- `ANNOTATIONS_OUTPUT_PATH`: The path where the annotaions should be stored. Should be a .json file.
- `ANNOTATE_MISSING_LINES`: Whether to annotate missing lines in the coverage report. Default is False.
Expand Down
19 changes: 9 additions & 10 deletions codecov/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
from codecov import log


# The dataclasses in this module are accessible in the template, which is overridable by the user.
# As a coutesy, we should do our best to keep the existing fields for backward compatibility,
# and if we really can't and can't add properties, at least bump the major version.
@dataclasses.dataclass
class CoverageMetadata:
version: str
Expand Down Expand Up @@ -43,6 +40,8 @@ class FileCoverage:
executed_lines: list[int]
missing_lines: list[int]
excluded_lines: list[int]
executed_branches: list[list[int]] | None
missing_branches: list[list[int]] | None
info: CoverageInfo


Expand All @@ -53,10 +52,6 @@ class Coverage:
files: dict[pathlib.Path, FileCoverage]


# The format for Diff Coverage objects may seem a little weird, because it
# was originally copied from diff-cover schema.


@dataclasses.dataclass
class FileDiffCoverage:
path: pathlib.Path
Expand Down Expand Up @@ -89,7 +84,7 @@ def compute_coverage(num_covered: int, num_total: int) -> decimal.Decimal:
return decimal.Decimal(num_covered) / decimal.Decimal(num_total)


def get_coverage_info(coverage_path: pathlib.Path) -> tuple[dict, Coverage]:
def get_coverage_info(coverage_path: pathlib.Path) -> Coverage:
try:
with coverage_path.open() as coverage_data:
json_coverage = json.loads(coverage_data.read())
Expand All @@ -100,7 +95,7 @@ def get_coverage_info(coverage_path: pathlib.Path) -> tuple[dict, Coverage]:
log.error('Invalid JSON format in coverage report file: %s', coverage_path)
raise

return json_coverage, extract_info(data=json_coverage)
return extract_info(data=json_coverage)


def extract_info(data: dict) -> Coverage:
Expand Down Expand Up @@ -129,6 +124,8 @@ def extract_info(data: dict) -> Coverage:
},
"missing_lines": [7],
"excluded_lines": [],
"executed_branches": [],
"missing_branches": [],
}
},
"totals": {
Expand Down Expand Up @@ -156,8 +153,10 @@ def extract_info(data: dict) -> Coverage:
pathlib.Path(path): FileCoverage(
path=pathlib.Path(path),
excluded_lines=file_data['excluded_lines'],
executed_lines=file_data['executed_lines'],
missing_lines=file_data['missing_lines'],
executed_lines=file_data['executed_lines'],
executed_branches=file_data.get('executed_branches'),
missing_branches=file_data.get('missing_branches'),
info=CoverageInfo(
covered_lines=file_data['summary']['covered_lines'],
num_statements=file_data['summary']['num_statements'],
Expand Down
5 changes: 3 additions & 2 deletions codecov/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def process_pr( # pylint: disable=too-many-locals
repo_info: github.RepositoryInfo,
pr_number: int,
) -> int:
_, coverage = coverage_module.get_coverage_info(coverage_path=config.COVERAGE_PATH)
coverage = coverage_module.get_coverage_info(coverage_path=config.COVERAGE_PATH)
base_ref = config.GITHUB_BASE_REF or repo_info.default_branch
pr_diff = github.get_pr_diff(github=gh, repository=config.GITHUB_REPOSITORY, pr_number=pr_number)
added_lines = coverage_module.parse_diff_output(diff=pr_diff)
diff_coverage = coverage_module.get_diff_coverage_info(coverage=coverage, added_lines=added_lines)
diff_coverage = coverage_module.get_diff_coverage_info(added_lines=added_lines, coverage=coverage)

if config.ANNOTATE_MISSING_LINES:
log.info('Generating annotations for missing lines.')
Expand Down Expand Up @@ -119,6 +119,7 @@ def process_pr( # pylint: disable=too-many-locals
base_template=template.read_template_file('comment.md.j2'),
marker=marker,
subproject_id=config.SUBPROJECT_ID,
branch_coverage=config.BRANCH_COVERAGE,
complete_project_report=config.COMPLETE_PROJECT_REPORT,
coverage_report_url=config.COVERAGE_REPORT_URL,
)
Expand Down
5 changes: 5 additions & 0 deletions codecov/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Config:
SUBPROJECT_ID: str | None = None
MINIMUM_GREEN: decimal.Decimal = decimal.Decimal('100')
MINIMUM_ORANGE: decimal.Decimal = decimal.Decimal('70')
BRANCH_COVERAGE: bool = False
SKIP_COVERAGE: bool = False
ANNOTATE_MISSING_LINES: bool = False
ANNOTATION_TYPE: str = 'warning'
Expand Down Expand Up @@ -78,6 +79,10 @@ def clean_annotate_missing_lines(cls, value: str) -> bool:
def clean_skip_coverage(cls, value: str) -> bool:
return str_to_bool(value)

@classmethod
def clean_branch_coverage(cls, value: str) -> bool:
return str_to_bool(value)

@classmethod
def clean_complete_project_report(cls, value: str) -> bool:
return str_to_bool(value)
Expand Down
2 changes: 2 additions & 0 deletions codecov/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def get_comment_markdown( # pylint: disable=too-many-arguments,too-many-locals
base_template: str,
marker: str,
subproject_id: str | None = None,
branch_coverage: bool = False,
complete_project_report: bool = False,
coverage_report_url: str | None = None,
):
Expand Down Expand Up @@ -128,6 +129,7 @@ def get_comment_markdown( # pylint: disable=too-many-arguments,too-many-locals
missing_lines_for_whole_project=missing_lines_for_whole_project,
subproject_id=subproject_id,
marker=marker,
branch_coverage=branch_coverage,
complete_project_report=complete_project_report,
coverage_report_url=coverage_report_url,
)
Expand Down
Loading