diff --git a/gitea/__init__.py b/gitea/__init__.py index 4ec9cb9..7b32042 100644 --- a/gitea/__init__.py +++ b/gitea/__init__.py @@ -10,4 +10,3 @@ from .gitea import ( Issue, Milestone, ) - diff --git a/gitea/basicGiteaApiObject.py b/gitea/basicGiteaApiObject.py index f27c8e0..0ef2225 100644 --- a/gitea/basicGiteaApiObject.py +++ b/gitea/basicGiteaApiObject.py @@ -1,22 +1,21 @@ -import logging -from .exceptions import ObjectIsInvalid +from .exceptions import ObjectIsInvalid + class BasicGiteaApiObject: - GET_API_OBJECT = "FORMAT/STINING/{argument}" PATCH_API_OBJECT = "FORMAT/STINING/{argument}" def __init__(self, gitea, id): self.__id = id self.gitea = gitea - self.deleted = False # set if .delete was called, so that an exception is risen + self.deleted = False # set if .delete was called, so that an exception is risen self.dirty_fields = set() def __eq__(self, other): return other.id == self.id if isinstance(other, type(self)) else False def __str__(self): - return "GiteaAPIObject (%s) id: %s"%(type(self),self.id) + return "GiteaAPIObject (%s) id: %s" % (type(self), self.id) def __hash__(self): return self.id @@ -29,12 +28,12 @@ class BasicGiteaApiObject: raise NotImplemented() def get_dirty_fields(self): - return {name: getattr(self,name) for name in self.dirty_fields} + return {name: getattr(self, name) for name in self.dirty_fields} @classmethod def parse_response(cls, gitea, result): id = int(result["id"]) - #gitea.logger.debug("Found api object of type %s (id: %s)" % (type(cls), id)) + # gitea.logger.debug("Found api object of type %s (id: %s)" % (type(cls), id)) api_object = cls(gitea, id=id) cls._initialize(gitea, api_object, result) return api_object @@ -60,15 +59,15 @@ class BasicGiteaApiObject: prop = property( (lambda name: lambda self: self.__get_var(name))(name)) setattr(cls, name, prop) - setattr(api_object, "_"+name, value) + setattr(api_object, "_" + name, value) - def __set_var(self,name,i): + def __set_var(self, name, i): if self.deleted: raise ObjectIsInvalid() self.dirty_fields.add(name) - setattr(self,"_"+name,i) + setattr(self, "_" + name, i) - def __get_var(self,name): + def __get_var(self, name): if self.deleted: raise ObjectIsInvalid() - return getattr(self,"_"+name) \ No newline at end of file + return getattr(self, "_" + name) diff --git a/gitea/exceptions.py b/gitea/exceptions.py index cc9d706..e6a683f 100644 --- a/gitea/exceptions.py +++ b/gitea/exceptions.py @@ -1,11 +1,14 @@ class AlreadyExistsException(Exception): pass + class NotFoundException(Exception): pass + class ObjectIsInvalid(Exception): pass + class ConflictException(Exception): - pass \ No newline at end of file + pass diff --git a/gitea/gitea.py b/gitea/gitea.py index a363a8b..daad989 100644 --- a/gitea/gitea.py +++ b/gitea/gitea.py @@ -299,6 +299,7 @@ class Comment(BasicGiteaApiObject): patchable_fields = {"body"} + class Commit(GiteaApiObject): def __init__(self, gitea, id: int): @@ -308,7 +309,6 @@ class Commit(GiteaApiObject): "author": lambda gitea, u: User.parse_response(gitea, u) } - @classmethod def request(cls, gitea, owner, repo): api_object = cls._request(gitea, {"owner": owner, "repo": repo}) @@ -317,11 +317,11 @@ class Commit(GiteaApiObject): @classmethod def parse_response(cls, gitea, result): id = result["sha"] - #gitea.logger.debug("Found api object of type %s (id: %s)" % (type(cls), id)) + # gitea.logger.debug("Found api object of type %s (id: %s)" % (type(cls), id)) api_object = cls(gitea, id=id) cls._initialize(gitea, api_object, result) # HACK - api_object.__setattr__('id', uuid.uuid1().int>>64) + api_object.__setattr__('id', uuid.uuid1().int >> 64) return api_object @@ -697,7 +697,7 @@ class Gitea: return user def create_repo(self, repoOwner, repoName: str, description: str = "", private: bool = False, autoInit=True, - gitignores:str=None, license:str=None, readme:str="Default", issue_labels:str=None ): + gitignores: str = None, license: str = None, readme: str = "Default", issue_labels: str = None): """ Create a Repository. Throws: AlreadyExistsException, if Repository exists already. diff --git a/gitea/giteaApiObject.py b/gitea/giteaApiObject.py index 9f0e9e7..2170445 100644 --- a/gitea/giteaApiObject.py +++ b/gitea/giteaApiObject.py @@ -1,8 +1,7 @@ from .basicGiteaApiObject import BasicGiteaApiObject -import logging + class GiteaApiObject(BasicGiteaApiObject): - GET_API_OBJECT = "FORMAT/STINING/{argument}" PATCH_API_OBJECT = "FORMAT/STINING/{argument}" @@ -19,7 +18,7 @@ class GiteaApiObject(BasicGiteaApiObject): def _request(cls, gitea, args): result = cls._get_gitea_api_object(gitea, args) api_object = cls.parse_response(gitea, result) - for key, value in args.items(): # hack: not all necessary request args in api result (e.g. repo name in issue) + for key, value in args.items(): # hack: not all necessary request args in api result (e.g. repo name in issue) if not hasattr(api_object, key): setattr(api_object, key, value) - return api_object \ No newline at end of file + return api_object