From a3aa1a51a8f475b0668e369b2f9f81714a42fe88 Mon Sep 17 00:00:00 2001 From: VarMonke Date: Tue, 19 Apr 2022 21:15:57 +0530 Subject: [PATCH] add properties --- Github/http.py | 4 ++-- Github/objects.py | 53 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Github/http.py b/Github/http.py index 953226a..f064710 100644 --- a/Github/http.py +++ b/Github/http.py @@ -261,6 +261,7 @@ class http: data['files'] = {} for file in files: data['files'][file.filename] = { + 'filename' : file.filename, # helps editing the file 'content': file.read() } data = json.dumps(data) @@ -284,5 +285,4 @@ class http: return await result.json() if result.status == 401: raise NoAuthProvided - raise RepositoryAlreadyExists - + raise RepositoryAlreadyExists \ No newline at end of file diff --git a/Github/objects.py b/Github/objects.py index 1d71690..4d17413 100644 --- a/Github/objects.py +++ b/Github/objects.py @@ -144,7 +144,6 @@ class Repository(APIObject): 'clone_url', 'stargazers_count', 'watchers_count', - 'forks', 'license', ) def __init__(self, response: dict, _http: http) -> None: @@ -177,6 +176,22 @@ class Repository(APIObject): def __repr__(self) -> str: return f'<{self.__class__.__name__}; id: {self.id}, name: {self.name!r}, owner: {self.owner!r}>' + @property + def is_fork(self) -> bool: + return self._response.get('fork') + + @property + def language(self) -> str: + return self._response.get('language') + + @property + def open_issues(self) -> int: + return self._response.get('open_issues') + + @property + def forks(self) -> int: + return self._response.get('forks') + class Issue(APIObject): __slots__ = ( 'id', @@ -212,6 +227,13 @@ class Issue(APIObject): def __repr__(self) -> str: return f'<{self.__class__.__name__}; id: {self.id}, title: {self.title}, user: {self.user}, created_at: {self.created_at}, state: {self.state}>' + @property + def updated_at(self) -> str: + return dt_formatter(self._response.get('updated_at')) + + @property + def html_url(self) -> str: + return self._response.get('html_url') #=== Gist stuff ===# @@ -237,14 +259,12 @@ class File: class Gist(APIObject): __slots__ = ( 'id', - 'description', 'html_url', 'node_id', 'files', 'public', 'owner', 'created_at', - 'comments', 'truncated', ) def __init__(self, response: dict, _http: http) -> None: @@ -264,6 +284,22 @@ class Gist(APIObject): def __repr__(self) -> str: return f'<{self.__class__.__name__}; id: {self.id}, owner: {self.owner}, created_at: {self.created_at}>' + @property + def updated_at(self) -> str: + return dt_formatter(self._response.get('updated_at')) + + @property + def comments(self) -> str: + return self._response.get('comments') + + @property + def discussion(self) -> str: + return self._response.get('discussion') + + @property + def raw(self) -> str: + return self._response + #=== Organization stuff ===# @@ -271,7 +307,6 @@ class Organization(APIObject): __slots__ = ( 'login', 'id', - 'html_url', 'is_verified', 'public_repos', 'public_gists', @@ -298,4 +333,12 @@ class Organization(APIObject): continue def __repr__(self): - return f'<{self.__class__.__name__}; login: {self.login!r}, id: {self.id}, html_url: {self.html_url}, is_verified: {self.is_verified}, public_repos: {self.public_repos}, public_gists: {self.public_gists}, created_at: {self.created_at}>' + return f'<{self.__class__.__name__}; login: {self.login!r}, id: {self.id}, is_verified: {self.is_verified}, public_repos: {self.public_repos}, public_gists: {self.public_gists}, created_at: {self.created_at}>' + + @property + def description(self): + return self._response.get('description') + + @property + def html_url(self): + return self._response.get('html_url') \ No newline at end of file