Skip to content

Commit 94446be

Browse files
committed
Github client: Upon receiving application/vnd.github.raw+json, treat as text
1 parent c7a6919 commit 94446be

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

coverage_comment/github_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,13 @@ def _http(
102102

103103
def response_contents(
104104
response: httpx.Response,
105-
) -> JsonObject | bytes:
105+
) -> JsonObject | str | bytes:
106106
if response.headers.get("content-type", "").startswith("application/json"):
107107
return response.json(object_hook=JsonObject)
108+
if response.headers.get("content-type", "").startswith(
109+
"application/vnd.github.raw+json"
110+
):
111+
return response.text
108112
return response.content
109113

110114

tests/unit/test_github_client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ 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_text(session, gh):
17+
session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})(
18+
text="foobar", headers={"content-type": "application/vnd.github.raw+json"}
19+
)
20+
21+
assert gh.repos("a/b").issues().get(a=1) == "foobar"
22+
23+
24+
def test_github_client__get_bytes(session, gh):
25+
session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})(
26+
text="foobar", headers={"content-type": "application/vnd.github.raw+json"}
27+
)
28+
29+
assert gh.repos("a/b").issues().get(a=1, bytes=True) == b"foobar"
30+
31+
1632
def test_github_client__get_headers(session, gh):
1733
session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})(
1834
json={"foo": "bar"},

0 commit comments

Comments
 (0)