diff --git a/README.md b/README.md index 63df4f9..8c7e554 100644 --- a/README.md +++ b/README.md @@ -2,14 +2,19 @@ Create a Coverage report comment on Github PR -run: - To generate the pytest coverage report ```bash pipenv run pytest tests --cov-branch --cov=codecov --cov-report=json:/tmp/report.json ``` +Permissions needed for the Github Token +`Contents:read` +`Pull requests:read` +`Pull requests:write` + +**run:** + ```bash GITHUB_REPOSITORY= \ COVERAGE_PATH= \ diff --git a/codecov/coverage.py b/codecov/coverage.py index c6f2037..58fd02a 100644 --- a/codecov/coverage.py +++ b/codecov/coverage.py @@ -261,7 +261,7 @@ def parse_line_number_diff_line(diff_line: str) -> Sequence[int]: Github API returns default context lines 3 at start and end, we need to remove them. """ start, length = (int(i) for i in (diff_line.split()[2][1:] + ',1').split(',')[:2]) - current_file_coverage = current_file and coverage.files[current_file] + current_file_coverage = current_file and coverage.files.get(current_file) # TODO: sometimes the file might not be in the coverage report # Then we might as well just return the whole range since they are also not covered @@ -270,7 +270,7 @@ def parse_line_number_diff_line(diff_line: str) -> Sequence[int]: # Alternatively, we can get the number of statements in the file from github API # But it can be not good performance-wise since we need to make a request for each file if not (current_file_coverage and current_file_coverage.executed_lines): - return range(start, start + length) + return range(start if start == 1 else start + 3, start + length) current_file_num_statements = current_file_coverage.executed_lines[-1] + 1 end = start + length