Skip to content

Commit

Permalink
Github client: Upon receiving application/vnd.github.raw+json, treat …
Browse files Browse the repository at this point in the history
…as text
  • Loading branch information
ewjoachim committed Feb 15, 2024
1 parent c7a6919 commit 94446be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
6 changes: 5 additions & 1 deletion coverage_comment/github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
16 changes: 16 additions & 0 deletions tests/unit/test_github_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit 94446be

Please sign in to comment.