Skip to content

Commit

Permalink
Github client: accept request headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ewjoachim committed Feb 15, 2024
1 parent 9af72a0 commit c7a6919
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions coverage_comment/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def __getattr__(self, attr):


class GitHub:

"""
GitHub client.
"""
Expand All @@ -58,9 +57,18 @@ def __init__(self, session: httpx.Client):
def __getattr__(self, attr):
return _Callable(self, "/%s" % attr)

def _http(self, method, path, *, bytes=False, **kw):
def _http(
self,
method: str,
path: str,
*,
bytes: bool = False,
headers: dict[str, str] | None = None,
**kw,
):
_method = method.lower()
requests_kwargs = {}
header_kwargs = {"headers": headers} if headers else {}
if _method == "get" and kw:
requests_kwargs = {"params": kw}

Expand All @@ -71,6 +79,7 @@ def _http(self, method, path, *, bytes=False, **kw):
_method.upper(),
path,
timeout=TIMEOUT,
**header_kwargs,
**requests_kwargs,
)
if bytes:
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def test_github_client__get(session, gh):
assert gh.repos("a/b").issues().get(a=1) == {"foo": "bar"}


def test_github_client__get_headers(session, gh):
session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})(
json={"foo": "bar"},
headers={"X-foo": "yay"},
)

assert gh.repos("a/b").issues().get(a=1, headers={"X-foo": "yay"}) == {"foo": "bar"}


def test_github_client__post_non_json(session, gh):
session.register("POST", "/repos/a/b/issues", timeout=60, json={"a": 1})()

Expand Down

0 comments on commit c7a6919

Please sign in to comment.