Skip to content

Commit d07a126

Browse files
committed
GitHub client: return text by default
1 parent 3efb5dd commit d07a126

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

coverage_comment/github_client.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,7 @@ def _http(
8383
**header_kwargs,
8484
**requests_kwargs,
8585
)
86-
if bytes:
87-
contents = response.content
88-
else:
89-
contents = response_contents(response)
86+
contents = response_contents(response=response, bytes=bytes)
9087

9188
try:
9289
response.raise_for_status()
@@ -103,14 +100,15 @@ def _http(
103100

104101
def response_contents(
105102
response: httpx.Response,
103+
bytes: bool,
106104
) -> JsonObject | str | bytes:
105+
if bytes:
106+
return response.content
107+
107108
if response.headers.get("content-type", "").startswith("application/json"):
108109
return response.json(object_hook=JsonObject)
109-
if response.headers.get("content-type", "").startswith(
110-
"application/vnd.github.raw+json"
111-
):
112-
return response.text
113-
return response.content
110+
111+
return response.text
114112

115113

116114
class JsonObject(dict):

tests/unit/test_github_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,4 @@ def test_github_client__get_error_non_json(session, gh):
7979
with pytest.raises(github_client.ApiError) as exc_info:
8080
gh.repos.get()
8181

82-
assert str(exc_info.value) == "b'{foobar'"
82+
assert str(exc_info.value) == "{foobar"

0 commit comments

Comments
 (0)