Skip to content

Commit c7a6919

Browse files
committed
Github client: accept request headers
1 parent 9af72a0 commit c7a6919

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

coverage_comment/github_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def __getattr__(self, attr):
4747

4848

4949
class GitHub:
50-
5150
"""
5251
GitHub client.
5352
"""
@@ -58,9 +57,18 @@ def __init__(self, session: httpx.Client):
5857
def __getattr__(self, attr):
5958
return _Callable(self, "/%s" % attr)
6059

61-
def _http(self, method, path, *, bytes=False, **kw):
60+
def _http(
61+
self,
62+
method: str,
63+
path: str,
64+
*,
65+
bytes: bool = False,
66+
headers: dict[str, str] | None = None,
67+
**kw,
68+
):
6269
_method = method.lower()
6370
requests_kwargs = {}
71+
header_kwargs = {"headers": headers} if headers else {}
6472
if _method == "get" and kw:
6573
requests_kwargs = {"params": kw}
6674

@@ -71,6 +79,7 @@ def _http(self, method, path, *, bytes=False, **kw):
7179
_method.upper(),
7280
path,
7381
timeout=TIMEOUT,
82+
**header_kwargs,
7483
**requests_kwargs,
7584
)
7685
if bytes:

tests/unit/test_github_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@ def test_github_client__get(session, gh):
1313
assert gh.repos("a/b").issues().get(a=1) == {"foo": "bar"}
1414

1515

16+
def test_github_client__get_headers(session, gh):
17+
session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})(
18+
json={"foo": "bar"},
19+
headers={"X-foo": "yay"},
20+
)
21+
22+
assert gh.repos("a/b").issues().get(a=1, headers={"X-foo": "yay"}) == {"foo": "bar"}
23+
24+
1625
def test_github_client__post_non_json(session, gh):
1726
session.register("POST", "/repos/a/b/issues", timeout=60, json={"a": 1})()
1827

0 commit comments

Comments
 (0)