1
Fork 0
mirror of https://github.com/RGBCube/GitHubWrapper synced 2025-05-18 06:55:09 +00:00

Fixing get_repo returning None for license, and erroring

This commit is contained in:
VarMonke 2022-03-29 20:02:12 +05:30
parent 45db6d5120
commit 0fa6f2b0fa
2 changed files with 6 additions and 3 deletions

View file

@ -80,7 +80,7 @@ class GHClient:
return User(await http.get_user(self.session, username), self.session) return User(await http.get_user(self.session, username), self.session)
async def get_repo(self, owner: str, repo_name: str) -> Repository: async def get_repo(self, owner: str, repo_name: str) -> Repository:
"""Fetch aGithub repository from it's name.""" """Fetch a Github repository from it's name."""
return Repository(await http.get_repo_from_name(self.session, owner, repo_name), self.session) return Repository(await http.get_repo_from_name(self.session, owner, repo_name), self.session)
async def get_org(self, org_name: str) -> Organization: async def get_org(self, org_name: str) -> Organization:

View file

@ -28,7 +28,7 @@ class Repository(APIOBJECT):
'stargazers_count', 'stargazers_count',
'watchers_count', 'watchers_count',
'forks', 'forks',
'license' 'license',
) )
def __init__(self, response: dict, session: aiohttp.ClientSession) -> None: def __init__(self, response: dict, session: aiohttp.ClientSession) -> None:
super().__init__(response, session) super().__init__(response, session)
@ -47,12 +47,15 @@ class Repository(APIOBJECT):
setattr(self, key, dt_formatter(value)) setattr(self, key, dt_formatter(value))
continue continue
if 'license' in key and value is None:
setattr(self, key, None)
else: else:
setattr(self, key, value) setattr(self, key, value)
continue continue
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<Repository; id: {self.id}, name: {self.name}, owner: {self.owner}, updated_at: {self.updated_at}, default_branch: {self.default_branch}, license: {self.license["name"]}>' return f'<Repository; id: {self.id}, name: {self.name}, owner: {self.owner}, updated_at: {self.updated_at}, default_branch: {self.default_branch}, license: {self.license}>'
@classmethod @classmethod
async def from_name(cls, session: aiohttp.ClientSession,owner: str, repo_name: str) -> 'Repository': async def from_name(cls, session: aiohttp.ClientSession,owner: str, repo_name: str) -> 'Repository':