diff --git a/coverage_comment/github_client.py b/coverage_comment/github_client.py index e6eb6efa..3057e1ec 100644 --- a/coverage_comment/github_client.py +++ b/coverage_comment/github_client.py @@ -102,9 +102,13 @@ def _http( def response_contents( response: httpx.Response, -) -> JsonObject | bytes: +) -> JsonObject | str | bytes: if response.headers.get("content-type", "").startswith("application/json"): return response.json(object_hook=JsonObject) + if response.headers.get("content-type", "").startswith( + "application/vnd.github.raw+json" + ): + return response.text return response.content diff --git a/tests/unit/test_github_client.py b/tests/unit/test_github_client.py index 94f1ce9b..3f07b271 100644 --- a/tests/unit/test_github_client.py +++ b/tests/unit/test_github_client.py @@ -13,6 +13,22 @@ def test_github_client__get(session, gh): assert gh.repos("a/b").issues().get(a=1) == {"foo": "bar"} +def test_github_client__get_text(session, gh): + session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})( + text="foobar", headers={"content-type": "application/vnd.github.raw+json"} + ) + + assert gh.repos("a/b").issues().get(a=1) == "foobar" + + +def test_github_client__get_bytes(session, gh): + session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})( + text="foobar", headers={"content-type": "application/vnd.github.raw+json"} + ) + + assert gh.repos("a/b").issues().get(a=1, bytes=True) == b"foobar" + + def test_github_client__get_headers(session, gh): session.register("GET", "/repos/a/b/issues", timeout=60, params={"a": 1})( json={"foo": "bar"},