Langenfeld 2020-10-14 14:44:05 +02:00
rodzic e9d45515d9
commit 0acbdbe125
5 zmienionych plików z 22 dodań i 22 usunięć

Wyświetl plik

@ -10,4 +10,3 @@ from .gitea import (
Issue, Issue,
Milestone, Milestone,
) )

Wyświetl plik

@ -1,22 +1,21 @@
import logging from .exceptions import ObjectIsInvalid
from .exceptions import ObjectIsInvalid
class BasicGiteaApiObject: class BasicGiteaApiObject:
GET_API_OBJECT = "FORMAT/STINING/{argument}" GET_API_OBJECT = "FORMAT/STINING/{argument}"
PATCH_API_OBJECT = "FORMAT/STINING/{argument}" PATCH_API_OBJECT = "FORMAT/STINING/{argument}"
def __init__(self, gitea, id): def __init__(self, gitea, id):
self.__id = id self.__id = id
self.gitea = gitea 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() self.dirty_fields = set()
def __eq__(self, other): def __eq__(self, other):
return other.id == self.id if isinstance(other, type(self)) else False return other.id == self.id if isinstance(other, type(self)) else False
def __str__(self): def __str__(self):
return "GiteaAPIObject (%s) id: %s"%(type(self),self.id) return "GiteaAPIObject (%s) id: %s" % (type(self), self.id)
def __hash__(self): def __hash__(self):
return self.id return self.id
@ -29,12 +28,12 @@ class BasicGiteaApiObject:
raise NotImplemented() raise NotImplemented()
def get_dirty_fields(self): 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 @classmethod
def parse_response(cls, gitea, result): def parse_response(cls, gitea, result):
id = int(result["id"]) 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) api_object = cls(gitea, id=id)
cls._initialize(gitea, api_object, result) cls._initialize(gitea, api_object, result)
return api_object return api_object
@ -60,15 +59,15 @@ class BasicGiteaApiObject:
prop = property( prop = property(
(lambda name: lambda self: self.__get_var(name))(name)) (lambda name: lambda self: self.__get_var(name))(name))
setattr(cls, name, prop) 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: if self.deleted:
raise ObjectIsInvalid() raise ObjectIsInvalid()
self.dirty_fields.add(name) 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: if self.deleted:
raise ObjectIsInvalid() raise ObjectIsInvalid()
return getattr(self,"_"+name) return getattr(self, "_" + name)

Wyświetl plik

@ -1,11 +1,14 @@
class AlreadyExistsException(Exception): class AlreadyExistsException(Exception):
pass pass
class NotFoundException(Exception): class NotFoundException(Exception):
pass pass
class ObjectIsInvalid(Exception): class ObjectIsInvalid(Exception):
pass pass
class ConflictException(Exception): class ConflictException(Exception):
pass pass

Wyświetl plik

@ -299,6 +299,7 @@ class Comment(BasicGiteaApiObject):
patchable_fields = {"body"} patchable_fields = {"body"}
class Commit(GiteaApiObject): class Commit(GiteaApiObject):
def __init__(self, gitea, id: int): def __init__(self, gitea, id: int):
@ -308,7 +309,6 @@ class Commit(GiteaApiObject):
"author": lambda gitea, u: User.parse_response(gitea, u) "author": lambda gitea, u: User.parse_response(gitea, u)
} }
@classmethod @classmethod
def request(cls, gitea, owner, repo): def request(cls, gitea, owner, repo):
api_object = cls._request(gitea, {"owner": owner, "repo": repo}) api_object = cls._request(gitea, {"owner": owner, "repo": repo})
@ -317,11 +317,11 @@ class Commit(GiteaApiObject):
@classmethod @classmethod
def parse_response(cls, gitea, result): def parse_response(cls, gitea, result):
id = result["sha"] 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) api_object = cls(gitea, id=id)
cls._initialize(gitea, api_object, result) cls._initialize(gitea, api_object, result)
# HACK # HACK
api_object.__setattr__('id', uuid.uuid1().int>>64) api_object.__setattr__('id', uuid.uuid1().int >> 64)
return api_object return api_object
@ -697,7 +697,7 @@ class Gitea:
return user return user
def create_repo(self, repoOwner, repoName: str, description: str = "", private: bool = False, autoInit=True, 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. """ Create a Repository.
Throws: Throws:
AlreadyExistsException, if Repository exists already. AlreadyExistsException, if Repository exists already.

Wyświetl plik

@ -1,8 +1,7 @@
from .basicGiteaApiObject import BasicGiteaApiObject from .basicGiteaApiObject import BasicGiteaApiObject
import logging
class GiteaApiObject(BasicGiteaApiObject): class GiteaApiObject(BasicGiteaApiObject):
GET_API_OBJECT = "FORMAT/STINING/{argument}" GET_API_OBJECT = "FORMAT/STINING/{argument}"
PATCH_API_OBJECT = "FORMAT/STINING/{argument}" PATCH_API_OBJECT = "FORMAT/STINING/{argument}"
@ -19,7 +18,7 @@ class GiteaApiObject(BasicGiteaApiObject):
def _request(cls, gitea, args): def _request(cls, gitea, args):
result = cls._get_gitea_api_object(gitea, args) result = cls._get_gitea_api_object(gitea, args)
api_object = cls.parse_response(gitea, result) 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): if not hasattr(api_object, key):
setattr(api_object, key, value) setattr(api_object, key, value)
return api_object return api_object