From 94446bee73394052e584de8c8383a758d35767c7 Mon Sep 17 00:00:00 2001 From: Joachim Jablon Date: Thu, 15 Feb 2024 22:04:57 +0100 Subject: [PATCH] Github client: Upon receiving application/vnd.github.raw+json, treat as text --- coverage_comment/github_client.py | 6 +++++- tests/unit/test_github_client.py | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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"},