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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<repository_name> \
COVERAGE_PATH=<path_to_coverage_report> \
Expand Down
4 changes: 2 additions & 2 deletions codecov/coverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down