feature: use apis to fetch diff instead of subprocess by ideepu · Pull Request #2 · ideepu/python-coverage-comment · GitHub
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
17 changes: 4 additions & 13 deletions codecov/coverage.py
15 changes: 15 additions & 0 deletions codecov/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ def get_pr_number(github: github_client.GitHub, config: settings.Config) -> int:
)


def get_pr_diff(github: github_client.GitHub, repository: str, pr_number: int) -> str:
try:
pull_request_diff = (
github.repos(repository)
.pulls(pr_number)
.get(use_text=True, headers={'Accept': 'application/vnd.github.v3.diff'})
)
except github_client.Forbidden as exc:
raise CannotGetPullRequest from exc
except github_client.NotFound as exc:
raise CannotGetPullRequest from exc

return pull_request_diff


def post_comment( # pylint: disable=too-many-arguments
github: github_client.GitHub,
me: str,
Expand Down
6 changes: 5 additions & 1 deletion codecov/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def __init__(self, session: httpx.Client):
def __getattr__(self, attr):
return _Callable(self, f'/{attr}')

def _http(self, method, path, *, use_bytes=False, **kw):
def _http(self, method, path, *, use_bytes=False, use_text=False, **kw):
_method = method.lower()
requests_kwargs = {}
headers = kw.pop('headers', {})
if _method == 'get' and kw:
requests_kwargs = {'params': kw}

Expand All @@ -61,10 +62,13 @@ def _http(self, method, path, *, use_bytes=False, **kw):
_method.upper(),
path,
timeout=TIMEOUT,
headers=headers,
**requests_kwargs,
)
if use_bytes:
contents = response.content
elif use_text:
contents = response.text
else:
contents = response_contents(response)

Expand Down
26 changes: 6 additions & 20 deletions codecov/main.py
76 changes: 0 additions & 76 deletions codecov/subprocess.py

This file was deleted.