From e9556635a08d7f755323df8a6e966c0a0859bb27 Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Fri, 5 May 2017 01:39:44 +0200 Subject: [PATCH 1/2] Updated the model to DRY Signed-off-by: Guyzmo --- gogs_client/entities.py | 730 +++++++++++++++------------------------- requirements.txt | 1 + setup.py | 2 +- tests/interface_test.py | 16 +- 4 files changed, 275 insertions(+), 474 deletions(-) diff --git a/gogs_client/entities.py b/gogs_client/entities.py index 673ceb4..43d5de6 100644 --- a/gogs_client/entities.py +++ b/gogs_client/entities.py @@ -12,583 +12,383 @@ def json_get(parsed_json, key): raise ValueError("JSON does not contain a {} field".format(key)) return parsed_json[key] +import attr -class GogsEntity(object): - def __init__(self, json): - self._json = json - - @property - def json(self): - return self._json +from collections import OrderedDict +@attr.s +class GogsEntity(object): + json = attr.ib() + @classmethod + def from_json(cls, parsed_json): + # with introspection, get arguments of the constructor + parsed_json['json'] = parsed_json.copy() + params = cls.__attrs_attrs__ + args = [] + kwargs = OrderedDict() + for param in params: + param_name = param.name.lstrip('_') + # if not a keyword argument + if param.default == attr.NOTHING: + args.append(json_get(parsed_json, param_name)) + # if it's a keyword argument + else: + kwargs[param_name] = parsed_json.get(param_name, None) + o = cls(*args, **kwargs) + return o + + +@attr.s(frozen=True) class GogsUser(GogsEntity): """ An immutable representation of a Gogs user """ - def __init__(self, user_id, username, full_name, email, avatar_url, json={}): - super(GogsUser, self).__init__(json=json) - self._id = user_id - self._username = username - self._full_name = full_name - self._email = email - self._avatar_url = avatar_url - - @staticmethod - def from_json(parsed_json): - user_id = json_get(parsed_json, "id") - username = json_get(parsed_json, "username") - full_name = json_get(parsed_json, "full_name") - email = parsed_json.get("email", None) - avatar_url = parsed_json.get("avatar_url", None) - return GogsUser(user_id=user_id, username=username, full_name=full_name, - email=email, avatar_url=avatar_url, json=parsed_json) - - @property # named user_id to avoid conflict with built-in id - def user_id(self): - """ - The user's id + """ + The user's id - :rtype: int - """ - return self._id + :rtype: int + """ + id = attr.ib() + user_id = property(lambda self: self.id) - @property - def username(self): - """ - The user's username + """ + The user's username - :rtype: str - """ - return self._username + :rtype: str + """ + username = attr.ib() - @property - def full_name(self): - """ - The user's full name + """ + The user's full name - :rtype: str - """ - return self._full_name + :rtype: str + """ + full_name = attr.ib() - @property - def email(self): - """ - The user's email address. Can be empty as a result of invalid authentication + """ + The user's email address. Can be empty as a result of invalid authentication - :rtype: str - """ - return self._email + :rtype: str + """ + email = attr.ib(default=None) - @property - def avatar_url(self): - """ - The user's avatar URL + """ + The user's avatar URL - :rtype: str - """ - return self._avatar_url + :rtype: str + """ + avatar_url = attr.ib(default=None) +@attr.s(frozen=True) class GogsRepo(GogsEntity): """ An immutable representation of a Gogs repository """ - def __init__(self, repo_id, owner, full_name, private, fork, parent, default_branch, - empty, size, urls, permissions, json={}): - super(GogsRepo, self).__init__(json=json) - self._repo_id = repo_id - self._owner = owner - self._full_name = full_name - self._private = private - self._fork = fork - self._parent = parent - self._default_branch = default_branch - self._empty = empty - self._size = size - self._urls = urls - self._permissions = permissions - - @staticmethod - def from_json(parsed_json): - repo_id = json_get(parsed_json, "id") - owner = GogsUser.from_json(json_get(parsed_json, "owner")) - full_name = json_get(parsed_json, "full_name") - private = json_get(parsed_json, "private") - fork = json_get(parsed_json, "fork") - parent = parsed_json.get("parent", None) - if parent: - parent = GogsRepo.from_json(parent) - default_branch = json_get(parsed_json, "default_branch") - empty = parsed_json.get("empty", None) - size = parsed_json.get("size", None) - urls = GogsRepo.Urls(json_get(parsed_json, "html_url"), json_get(parsed_json, "clone_url"), - json_get(parsed_json, "ssh_url")) - permissions = GogsRepo.Permissions.from_json(json_get(parsed_json, "permissions")) - return GogsRepo(repo_id=repo_id, owner=owner, full_name=full_name, private=private, fork=fork, - parent=parent, default_branch=default_branch, empty=empty, size=size, - urls=urls, permissions=permissions, json=parsed_json) - - @property # named repo_id to avoid conflict with built-in id - def repo_id(self): - """ - The repository's id + """ + The repository's id - :rtype: int - """ - return self._repo_id + :rtype: int + """ + id = attr.ib() + repo_id = property(lambda self: self.id) - @property - def owner(self): - """ - The owner of the repository + """ + The owner of the repository - :rtype: entities.GogsUser - """ - return self._owner + :rtype: entities.GogsUser + """ + owner = attr.ib(convert=lambda parsed_json:GogsUser.from_json(parsed_json)) + + """ + The full name of the repository + :rtype: str + """ + full_name = attr.ib() + + """ + Whether the repository is private + + :rtype: bool + """ + private = attr.ib() + + """ + Whether the repository is a fork + + :rtype: bool + """ + fork = attr.ib() + + """ + The name of the default branch + + :rtype: str + """ + default_branch = attr.ib() + + """ + URLs of the repository + + :rtype: GogsRepo.Urls + """ + _ssh_url = attr.ib() + _html_url = attr.ib() + _clone_url = attr.ib() @property - def full_name(self): + def urls(self): + return GogsRepo.Urls(self._html_url, self._clone_url,self._ssh_url) + + """ + Permissions for the repository + + :rtype: GogsRepo.Permissions + """ + permissions = attr.ib(convert=lambda data:GogsRepo.Permissions.from_json(data)) + + """ + Gets the repository's parent, when a fork + + :rtype: GogsRepo + """ + parent = attr.ib(convert=lambda data:GogsRepo.from_json(data) if data else None, default=None) + + """ + Whether the repository is empty + + :rtype: bool + """ + empty = attr.ib(default=None) + + """ + Size of the repository in kilobytes + + :rtype: int + """ + size = attr.ib(default=None) + + @attr.s(frozen=True) + class Urls(object): """ - The full name of the repository + URL for the repository's webpage :rtype: str """ - return self._full_name + html_url = attr.ib() - @property - def private(self): """ - Whether the repository is private + URL for cloning the repository (via HTTP) - :rtype: bool + :rtype: str """ - return self._private + clone_url = attr.ib() - @property - def fork(self): """ - Whether the repository is a fork + URL for cloning the repository via SSH - :rtype: bool + :rtype: str """ - return self._fork + ssh_url = attr.ib() - @property - def parent(self): + @attr.s(frozen=True) + class Permissions(GogsEntity): """ - Gets the repository's parent, when a fork + Whether the user that requested this repository has admin permissions - :rtype: GogsRepo + :rtype: bool """ - return self._parent + admin = attr.ib(default=False) - @property - def default_branch(self): """ - The name of the default branch + Whether the user that requested this repository has push permissions - :rtype: str + :rtype: bool """ - return self._default_branch + push = attr.ib(default=False) - @property - def empty(self): """ - Whether the repository is empty + Whether the user that requested this repository has pull permissions :rtype: bool """ - return self._empty + pull = attr.ib(default=False) - @property - def size(self): + @attr.s(frozen=True) + class Hook(GogsEntity): """ - Size of the repository in kilobytes + The hook's id number :rtype: int """ - return self._size + id = attr.ib() + hook_id = property(lambda self: self.id) - @property - def urls(self): """ - URLs of the repository + The hook's type (gogs, slack, etc.) - :rtype: GogsRepo.Urls + :rtype: str """ - return self._urls + type = attr.ib() + hook_type = property(lambda self: self.type) - @property - def permissions(self): """ - Permissions for the repository + The events that fire the hook - :rtype: GogsRepo.Permissions + :rtype: List[str] """ - return self._permissions + events = attr.ib() - class Urls(object): - def __init__(self, html_url, clone_url, ssh_url): - self._html_url = html_url - self._clone_url = clone_url - self._ssh_url = ssh_url - - @property - def html_url(self): - """ - URL for the repository's webpage - - :rtype: str - """ - return self._html_url - - @property - def clone_url(self): - """ - URL for cloning the repository (via HTTP) - - :rtype: str - """ - return self._clone_url - - @property - def ssh_url(self): - """ - URL for cloning the repository via SSH - - :rtype: str - """ - return self._ssh_url - - class Permissions(GogsEntity): - def __init__(self, admin, push, pull, json={}): - super(GogsRepo.Permissions, self).__init__(json=json) - self._admin = admin - self._push = push - self._pull = pull - - @staticmethod - def from_json(parsed_json): - admin = parsed_json.get("admin", False) - push = parsed_json.get("push", False) - pull = parsed_json.get("pull", False) - return GogsRepo.Permissions(admin, push, pull, parsed_json) - - @property - def admin(self): - """ - Whether the user that requested this repository has admin permissions - - :rtype: bool - """ - return self._admin - - @property - def push(self): - """ - Whether the user that requested this repository has push permissions - - :rtype: bool - """ - return self._push - - @property - def pull(self): - """ - Whether the user that requested this repository has pull permissions - - :rtype: bool - """ - return self._pull - - class Hook(GogsEntity): - def __init__(self, hook_id, hook_type, events, active, config, json={}): - super(GogsRepo.Hook, self).__init__(json=json) - self._id = hook_id - self._type = hook_type - self._events = events - self._active = active - self._config = config - - @staticmethod - def from_json(parsed_json): - hook_id = json_get(parsed_json, "id") - hook_type = json_get(parsed_json, "type") - events = json_get(parsed_json, "events") - active = json_get(parsed_json, "active") - config = json_get(parsed_json, "config") - return GogsRepo.Hook(hook_id=hook_id, hook_type=hook_type, events=events, active=active, - config=config, json=parsed_json) - - @property # named hook_id to avoid conflict with built-in id - def hook_id(self): - """ - The hook's id number - - :rtype: int - """ - return self._id - - @property # named hook_type to avoid conflict with built-in type - def hook_type(self): - """ - The hook's type (gogs, slack, etc.) - - :rtype: str - """ - return self._type - - @property - def events(self): - """ - The events that fire the hook - - :rtype: List[str] - """ - return self._events - - @property - def active(self): - """ - Whether the hook is active - - :rtype: bool - """ - return self._active - - @property - def config(self): - """ - Config of the hook. Possible keys include ``"content_type"``, ``"url"``, ``"secret"`` - - :rtype: dict - """ - return self._config + """ + Whether the hook is active - class DeployKey(GogsEntity): - def __init__(self, key_id, key, url, title, created_at, read_only, json={}): - super(GogsRepo.DeployKey, self).__init__(json=json) - self._id = key_id - self._key = key - self._url = url - self._title = title - self._created_at = created_at - self._read_only = read_only - - @staticmethod - def from_json(parsed_json): - key_id = json_get(parsed_json, "id") - key = json_get(parsed_json, "key") - url = json_get(parsed_json, "url") - title = json_get(parsed_json, "title") - created_at = json_get(parsed_json, "created_at") - read_only = json_get(parsed_json, "read_only") - - return GogsRepo.DeployKey(key_id=key_id, key=key, url=url, - title=title, created_at=created_at, - read_only=read_only, json=parsed_json) - - @property # named key_id to avoid conflict with built-in id - def key_id(self): - """ - The key's id number - - :rtype: int - """ - return self._id - - @property - def key(self): - """ - The content of the key - - :rtype: str - """ - return self._key - - @property - def url(self): - """ - URL where the key can be found - - :rtype: str - """ - return self._url - - @property - def title(self): - """ - The name of the key - - :rtype: str - """ - return self._title - - @property - def created_at(self): - """ - Creation date of the key - - :rtype: str - """ - return self._created_at - - @property - def read_only(self): - """ - Whether key is read-only - - :rtype: bool - """ - return self._read_only + :rtype: bool + """ + active = attr.ib() + """ + Config of the hook. Possible keys include ``"content_type"``, ``"url"``, ``"secret"`` -class GogsOrg(GogsEntity): - """ - An immutable representation of a Gogs Organization - """ + :rtype: dict + """ + config = attr.ib() - def __init__(self, org_id, username, full_name, avatar_url, description, website, location, json={}): - super(GogsOrg, self).__init__(json=json) - self._id = org_id - self._username = username - self._full_name = full_name - self._avatar_url = avatar_url - self._description = description - self._website = website - self._location = location - - @staticmethod - def from_json(parsed_json): - org_id = json_get(parsed_json, "id") - username = json_get(parsed_json, "username") - full_name = json_get(parsed_json, "full_name") - avatar_url = json_get(parsed_json, "avatar_url") - description = json_get(parsed_json, "description") - website = json_get(parsed_json, "website") - location = json_get(parsed_json, "location") - return GogsOrg(org_id=org_id, username=username, full_name=full_name, - avatar_url=avatar_url, description=description, - website=website, location=location, json=parsed_json) - - @property # named org_id to avoid conflict with built-in id - def org_id(self): - """ - The organization's id + @attr.s(frozen=True) + class DeployKey(GogsEntity): + """ + The key's id number :rtype: int """ - return self._id + id = attr.ib() + key_id = property(lambda self: self.id) - @property - def username(self): """ - Organization's username + The content of the key :rtype: str """ - return self._username + key = attr.ib() - @property - def full_name(self): """ - Organization's full name + URL where the key can be found :rtype: str """ - return self._full_name + url = attr.ib() - @property - def avatar_url(self): """ - Organization's avatar url + The name of the key :rtype: str """ - return self._avatar_url + title = attr.ib() - @property - def description(self): """ - Organization's description + Creation date of the key :rtype: str """ - return self._description + created_at = attr.ib() - @property - def website(self): """ - Organization's website address + Whether key is read-only - :rtype: str + :rtype: bool """ - return self._website + read_only = attr.ib() - @property - def location(self): - """ - Organization's location - :rtype: str - """ - return self._location +@attr.s(frozen=True) +class GogsOrg(GogsEntity): + """ + An immutable representation of a Gogs Organization + """ + """ + The organization's id + + :rtype: int + """ + id = attr.ib() + org_id = property(lambda self: self.id) + + """ + Organization's username + :rtype: str + """ + username = attr.ib() + + """ + Organization's full name + + :rtype: str + """ + full_name = attr.ib() + + """ + Organization's avatar url + + :rtype: str + """ + avatar_url = attr.ib() + + """ + Organization's description + + :rtype: str + """ + description = attr.ib() + + """ + Organization's website address + + :rtype: str + """ + website = attr.ib() + + """ + Organization's location + + :rtype: str + """ + location = attr.ib() + +@attr.s(frozen=True) class GogsTeam(GogsEntity): """ An immutable representation of a Gogs organization team """ - def __init__(self, team_id, name, description, permission, json={}): - super(GogsTeam, self).__init__(json=json) - self._id = team_id - self._name = name - self._description = description - self._permission = permission - @staticmethod - def from_json(parsed_json): - team_id = json_get(parsed_json, "id") - name = json_get(parsed_json, "name") - description = json_get(parsed_json, "description") - permission = json_get(parsed_json, "permission") - return GogsTeam(team_id=team_id, name=name, description=description, - permission=permission, json=parsed_json) + """ + Team's id - @property # named team_id to avoid conflict with built-in id - def team_id(self): - """ - Team's id + :rtype: int + """ + id = attr.ib() + team_id = property(lambda self: self.id) - :rtype: int - """ - return self._id + """ + Team name - @property - def name(self): - """ - Team name + :rtype: str + """ + name = attr.ib() - :rtype: str - """ - return self._name + """ + Description of the team - @property - def description(self): - """ - Description of the team + :rtype: str + """ + description = attr.ib() - :rtype: str - """ - return self._description + """ + Team permission, can be read, write or admin, default is read - @property - def permission(self): - """ - Team permission, can be read, write or admin, default is read + :rtype: int + """ + permission = attr.ib() - :rtype: int - """ - return self._permission diff --git a/requirements.txt b/requirements.txt index f38dacc..fd58773 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ future requests +attrs diff --git a/setup.py b/setup.py index 189a940..d0f9573 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,6 @@ ], keywords=["gogs", "http", "client"], packages=find_packages(), - install_requires=["future", "requests"], + install_requires=["future", "requests", "attrs"], test_suite="tests" ) diff --git a/tests/interface_test.py b/tests/interface_test.py index 4a59795..4377816 100644 --- a/tests/interface_test.py +++ b/tests/interface_test.py @@ -344,7 +344,7 @@ def callback(request): self.assertRegexpMatches(str(data["active"]), r"[tT]rue") self.assertRegexpMatches(str(data["admin"]), r"[fF]alse") self.assertRegexpMatches(str(data["allow_git_hook"]), r"[fF]alse") - self.assertNotIn("source_id", data) + self.assertNotIn("id", data) self.assertNotIn("location", data) self.assertNotIn("allow_import_local", data) return 200, {}, self.user_json_str @@ -585,7 +585,7 @@ def check_for_basic_auth(self, request): self.assertEqual(request.headers["Authorization"], "Basic {}".format(b64)) def assert_repos_equal(self, repo, expected): - self.assertEqual(repo.repo_id, expected.repo_id) + self.assertEqual(repo.id, expected.id) self.assert_users_equals(repo.owner, expected.owner) self.assertEqual(repo.full_name, expected.full_name) self.assertEqual(repo.private, expected.private) @@ -602,7 +602,7 @@ def assert_repos_equal(self, repo, expected): self.assertEqual(repo.permissions.pull, expected.permissions.pull) def assert_users_equals(self, user, expected): - self.assertEqual(user.user_id, expected.user_id) + self.assertEqual(user.id, expected.id) self.assertEqual(user.username, expected.username) self.assertEqual(user.full_name, expected.full_name) self.assertEqual(user.email, expected.email) @@ -613,14 +613,14 @@ def assert_tokens_equals(self, token, expected): self.assertEqual(token.token, expected.token) def assert_hooks_equals(self, hook, expected): - self.assertEqual(hook.hook_id, expected.hook_id) - self.assertEqual(hook.hook_type, expected.hook_type) + self.assertEqual(hook.id, expected.id) + self.assertEqual(hook.type, expected.type) self.assertEqual(hook.events, expected.events) self.assertEqual(hook.config, expected.config) self.assertEqual(hook.active, expected.active) def assert_org_equals(self, org, expected): - self.assertEqual(org.org_id, expected.org_id) + self.assertEqual(org.id, expected.id) self.assertEqual(org.username, expected.username) self.assertEqual(org.full_name, expected.full_name) self.assertEqual(org.avatar_url, expected.avatar_url) @@ -629,13 +629,13 @@ def assert_org_equals(self, org, expected): self.assertEqual(org.location, expected.location) def assert_team_equals(self, team, expected): - self.assertEqual(team.team_id, expected.team_id) + self.assertEqual(team.id, expected.id) self.assertEqual(team.name, expected.name) self.assertEqual(team.description, expected.description) self.assertEqual(team.permission, expected.permission) def assert_keys_equals(self, key, expected): - self.assertEqual(key.key_id, expected.key_id) + self.assertEqual(key.id, expected.id) self.assertEqual(key.title, expected.title) self.assertEqual(key.url, expected.url) self.assertEqual(key.key, expected.key) From 2abee71c4a1bbb567116c6bb8e264d2cf0e929f2 Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Tue, 9 May 2017 18:06:52 +0200 Subject: [PATCH 2/2] Updated sphinx documentation for new DRY style Signed-off-by: Guyzmo --- docs/conf.py | 13 +- docs/entities.rst | 6 + gogs_client/entities.py | 295 +++++++++++++++++----------------------- 3 files changed, 142 insertions(+), 172 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4bfa784..d1b1e4a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -335,6 +335,15 @@ # texinfo_no_detailmenu = False +autodoc_member_order = 'bysource' + +import attr + +def process_signature(app, what, name, obj, options, signature, + return_annotation): + if isinstance(obj, attr._make.Attribute): + obj.__class__.__repr__ = lambda *a, **k: None + def maybe_skip_member(app, what, name, obj, skip, options): # print (what, name, obj, skip) if type(obj) == property: @@ -344,12 +353,14 @@ def maybe_skip_member(app, what, name, obj, skip, options): return False whitelisted_init_classes = ["GogsApi", "Token", "UsernamePassword", "Builder"] if name == "__init__": - return obj.im_class.__name__ not in whitelisted_init_classes + if hasattr(obj, 'im_class'): + return obj.im_class.__name__ not in whitelisted_init_classes blacklisted_names = ["update_kwargs"] return skip or (name in blacklisted_names) def setup(app): app.connect('autodoc-skip-member', maybe_skip_member) + app.connect('autodoc-process-signature', process_signature) def add_directive_header(self, sig): ModuleLevelDocumenter.add_directive_header(self, sig) diff --git a/docs/entities.rst b/docs/entities.rst index 0e82e72..8a89b69 100644 --- a/docs/entities.rst +++ b/docs/entities.rst @@ -41,3 +41,9 @@ GogsTeam .. autoclass:: gogs_client.entities::GogsTeam() :members: + +GogsEntity +---------- + +.. autoclass:: gogs_client.entities::GogsEntity() + :members: diff --git a/gogs_client/entities.py b/gogs_client/entities.py index 43d5de6..50d861e 100644 --- a/gogs_client/entities.py +++ b/gogs_client/entities.py @@ -18,9 +18,22 @@ def json_get(parsed_json, key): @attr.s class GogsEntity(object): + """ + Base class for an entity defined by the API + + """ + json = attr.ib() + """ + :ivar json: Contains the json data + :vartype: dict + """ + @classmethod def from_json(cls, parsed_json): + """ + Factory function to build an object based on JSON data + """ # with introspection, get arguments of the constructor parsed_json['json'] = parsed_json.copy() params = cls.__attrs_attrs__ @@ -37,46 +50,38 @@ def from_json(cls, parsed_json): o = cls(*args, **kwargs) return o - @attr.s(frozen=True) class GogsUser(GogsEntity): """ An immutable representation of a Gogs user """ + id = attr.ib() """ - The user's id - - :rtype: int + The user's id (as *int*) """ - id = attr.ib() user_id = property(lambda self: self.id) - """ - The user's username + The user's id (as *int*) - *deprecated* + """ - :rtype: str + """ + The user's username (as *str*) """ username = attr.ib() """ - The user's full name - - :rtype: str + The user's full name (as *str*) """ full_name = attr.ib() """ - The user's email address. Can be empty as a result of invalid authentication - - :rtype: str + The user's email address. Can be empty as a result of invalid authentication (as *str*) """ email = attr.ib(default=None) """ - The user's avatar URL - - :rtype: str + The user's avatar URL (as *str*) """ avatar_url = attr.ib(default=None) @@ -87,218 +92,182 @@ class GogsRepo(GogsEntity): An immutable representation of a Gogs repository """ + id = attr.ib() """ - The repository's id - - :rtype: int + The repository's id (as *int*) """ - id = attr.ib() - repo_id = property(lambda self: self.id) + repo_id = property(lambda self: self.id) """ - The owner of the repository - - :rtype: entities.GogsUser + The repository's id (as *int*) - *deprecated* """ - owner = attr.ib(convert=lambda parsed_json:GogsUser.from_json(parsed_json)) + owner = attr.ib(convert=lambda parsed_json:GogsUser.from_json(parsed_json)) """ - The full name of the repository - - :rtype: str + The owner of the repository (as *:obj:`GogsUser`*) """ - full_name = attr.ib() + full_name = attr.ib() """ - Whether the repository is private - - :rtype: bool + The full name of the repository (as *str*) """ - private = attr.ib() + private = attr.ib() """ - Whether the repository is a fork - - :rtype: bool + Whether the repository is private (as *bool*) """ - fork = attr.ib() + fork = attr.ib() """ - The name of the default branch - - :rtype: str + Whether the repository is a fork (as *bool*) """ - default_branch = attr.ib() + default_branch = attr.ib() """ - URLs of the repository - - :rtype: GogsRepo.Urls + The name of the default branch (as *str*) """ + _ssh_url = attr.ib() _html_url = attr.ib() _clone_url = attr.ib() @property def urls(self): + """ + URLs of the repository (as *:obj:`GogsRepo.Urls`*) + """ return GogsRepo.Urls(self._html_url, self._clone_url,self._ssh_url) + permissions = attr.ib(convert=lambda data:GogsRepo.Permissions.from_json(data)) """ - Permissions for the repository - - :rtype: GogsRepo.Permissions + Permissions for the repository (as *:obj:`GogsRepo.Permissions`*) """ - permissions = attr.ib(convert=lambda data:GogsRepo.Permissions.from_json(data)) + parent = attr.ib(convert=lambda data:GogsRepo.from_json(data) if data else None, default=None) """ - Gets the repository's parent, when a fork - - :rtype: GogsRepo + Gets the repository's parent, when a fork (as *:obj:`GogsRepo`*) """ - parent = attr.ib(convert=lambda data:GogsRepo.from_json(data) if data else None, default=None) + empty = attr.ib(default=None) """ - Whether the repository is empty - - :rtype: bool + Whether the repository is empty (as *bool*) """ - empty = attr.ib(default=None) + size = attr.ib(default=None) """ - Size of the repository in kilobytes - - :rtype: int + Size of the repository in kilobytes (as *int*) """ - size = attr.ib(default=None) @attr.s(frozen=True) class Urls(object): """ - URL for the repository's webpage - - :rtype: str + Class representating the possible URL for a resource """ - html_url = attr.ib() + html_url = attr.ib() """ - URL for cloning the repository (via HTTP) - - :rtype: str + URL for the repository's webpage (as *str*) """ - clone_url = attr.ib() + clone_url = attr.ib() """ - URL for cloning the repository via SSH - - :rtype: str + URL for cloning the repository (via HTTP) (as *str*) """ + ssh_url = attr.ib() + """ + URL for cloning the repository via SSH (as *str*) + """ @attr.s(frozen=True) class Permissions(GogsEntity): """ - Whether the user that requested this repository has admin permissions - - :rtype: bool + Class representating the permession of a resource """ admin = attr.ib(default=False) - """ - Whether the user that requested this repository has push permissions - - :rtype: bool + Whether the user that requested this repository has admin permissions (as *bool*) """ - push = attr.ib(default=False) + push = attr.ib(default=False) """ - Whether the user that requested this repository has pull permissions - - :rtype: bool + Whether the user that requested this repository has push permissions (as *bool*) """ + pull = attr.ib(default=False) + """ + Whether the user that requested this repository has pull permissions (as *bool*) + """ @attr.s(frozen=True) class Hook(GogsEntity): + id = attr.ib() """ - The hook's id number - - :rtype: int + The hook's id number (as *int*) """ - id = attr.ib() hook_id = property(lambda self: self.id) - """ - The hook's type (gogs, slack, etc.) - - :rtype: str + same as id (as *int*) - *deprecated* """ + type = attr.ib() + """ + The hook's type (gogs, slack, etc.) (as *str*) + """ hook_type = property(lambda self: self.type) - """ - The events that fire the hook - - :rtype: List[str] + same as type (as *str*) - *deprecated* """ - events = attr.ib() + events = attr.ib() """ - Whether the hook is active - - :rtype: bool + The events that fire the hook (as *List[str]*) """ - active = attr.ib() + active = attr.ib() """ - Config of the hook. Possible keys include ``"content_type"``, ``"url"``, ``"secret"`` - - :rtype: dict + Whether the hook is active (as *bool*) """ + config = attr.ib() + """ + Config of the hook. Possible keys include ``"content_type"``, ``"url"``, ``"secret"`` (as *dict*) + """ @attr.s(frozen=True) class DeployKey(GogsEntity): + id = attr.ib() """ - The key's id number - - :rtype: int + The key's id number (as *int*) """ - id = attr.ib() key_id = property(lambda self: self.id) - """ - The content of the key - - :rtype: str + The key's id number (as *int*) """ - key = attr.ib() + key = attr.ib() """ - URL where the key can be found - - :rtype: str + The content of the key (as *str*) """ - url = attr.ib() + url = attr.ib() """ - The name of the key - - :rtype: str + URL where the key can be found (as *str*) """ - title = attr.ib() + title = attr.ib() """ - Creation date of the key - - :rtype: str + The name of the key (as *str*) """ - created_at = attr.ib() + created_at = attr.ib() """ - Whether key is read-only - - :rtype: bool + Creation date of the key (as *str*) """ + read_only = attr.ib() + """ + Whether key is read-only (as *bool*) + """ @attr.s(frozen=True) @@ -307,55 +276,44 @@ class GogsOrg(GogsEntity): An immutable representation of a Gogs Organization """ + id = attr.ib() """ - The organization's id - - :rtype: int + The organization's id (as *int*) """ - id = attr.ib() org_id = property(lambda self: self.id) - """ - Organization's username - - :rtype: str + same as id (as *int*) - *deprecated* """ - username = attr.ib() + username = attr.ib() """ - Organization's full name - - :rtype: str + Organization's username (as *str*) """ - full_name = attr.ib() + full_name = attr.ib() """ - Organization's avatar url - - :rtype: str + Organization's full name (as *str*) """ - avatar_url = attr.ib() + avatar_url = attr.ib() """ - Organization's description - - :rtype: str + Organization's avatar url (as *str*) """ - description = attr.ib() + description = attr.ib() """ - Organization's website address - - :rtype: str + Organization's description (as *str*) """ - website = attr.ib() + website = attr.ib() """ - Organization's location - - :rtype: str + Organization's website address (as *str*) """ + location = attr.ib() + """ + Organization's location (as *str*) + """ @attr.s(frozen=True) class GogsTeam(GogsEntity): @@ -363,32 +321,27 @@ class GogsTeam(GogsEntity): An immutable representation of a Gogs organization team """ + id = attr.ib() """ - Team's id - - :rtype: int + Team's id (as *int*) """ - id = attr.ib() team_id = property(lambda self: self.id) - """ - Team name - - :rtype: str + Same as id (as *int*) - *deprecated* """ - name = attr.ib() + name = attr.ib() """ - Description of the team - - :rtype: str + Team name (as *str*) """ - description = attr.ib() + description = attr.ib() """ - Team permission, can be read, write or admin, default is read - - :rtype: int + Description of the team (as *str*) """ + permission = attr.ib() + """ + Team permission, can be read, write or admin, default is read (as *int*) + """