Skip to content

Commit 61a07a7

Browse files
committed
fixed contenttype and contentNode parsing
1 parent 875c723 commit 61a07a7

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

asyncPyGithub/Repository.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from typing_extensions import Self
44

55
from ._types import (
6+
ContentNode,
67
ContentTree,
7-
ContentTreeJSON,
88
Contributor,
99
ErrorMessage,
1010
FullRepository,
@@ -541,6 +541,7 @@ async def get_repo_content(
541541
mediareturntype = "application/vnd.github+json"
542542

543543
try:
544+
# print(f">> Fetching content from repos/{owner}/{repo}/contents/{path} with mediatype {mediatype}")
544545
res = await cls.req(
545546
"GET",
546547
f"repos/{owner}/{repo}/contents/{path}",
@@ -560,7 +561,12 @@ async def get_repo_content(
560561
case "raw" | "html":
561562
return (res.status_code, res.content)
562563
case _:
563-
return (res.status_code, ContentTree(**res.json()))
564+
data = res.json()
565+
# If the API returned a file, it will not have an 'entries' key.
566+
if "entries" in data:
567+
return (res.status_code, ContentTree(**data))
568+
569+
return (res.status_code, ContentNode(**data))
564570
except Exception as e:
565571
return (
566572
500,

asyncPyGithub/_types/content.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
import string
2-
from datetime import datetime
31
from typing import (
4-
Any,
5-
Dict,
62
List,
7-
Literal,
83
NotRequired,
94
Optional,
105
TypedDict,
@@ -27,7 +22,7 @@ class ContentLink(BaseModel):
2722

2823
class ContentNodeJSON(TypedDict):
2924
type: str
30-
size: str
25+
size: int
3126
name: str
3227
path: str
3328
sha: str
@@ -41,7 +36,7 @@ class ContentNodeJSON(TypedDict):
4136

4237
class ContentNode(BaseModel):
4338
type: str
44-
size: str
39+
size: int
4540
name: str
4641
path: str
4742
sha: str

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "asyncPyGithub"
7-
version = "0.1.0.1"
7+
version = "0.1.0.3"
88
description = "Async Python wrapper for the GitHub API"
99
readme = "README.md"
1010
license = "MIT"

0 commit comments

Comments
 (0)