Skip to content

Commit 6a33e40

Browse files
committed
Fix docs and cleanups
1 parent c3ee062 commit 6a33e40

File tree

8 files changed

+225
-270
lines changed

8 files changed

+225
-270
lines changed

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,3 @@ ENV/
9191
# IDE files
9292
.idea/
9393

94-
# DRONE file
95-
.drone.yml

docs/entities.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Gogs Entities
22
=============
33

4-
This pages documents classes provided by ``gogs_client`` module that represent entities
5-
(e.g. users and repositories) in a `Gogs <https://gogs.io/>`_ server.
4+
This page documents the classes provided by ``gogs_client`` module that represent entities
5+
(e.g. users, repositories) in a `Gogs <https://gogs.io/>`_ server.
66

77
.. py:currentmodule:: gogs_client.entities
88
@@ -21,8 +21,11 @@ This pages documents classes provided by ``gogs_client`` module that represent e
2121
.. autoclass:: gogs_client.entities::GogsRepo.Hook()
2222
:members:
2323

24+
.. autoclass:: gogs_client.entities::GogsRepo.DeployKey()
25+
:members:
26+
2427
.. autoclass:: gogs_client.entities::GogsOrg()
2528
:members:
2629

27-
.. autoclass:: gogs_client.entities::GogsOrg.Team()
28-
:members:
30+
.. autoclass:: gogs_client.entities::GogsTeam()
31+
:members:

gogs_client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from gogs_client.auth import Authentication, Token, UsernamePassword
2-
from gogs_client.entities import GogsUser, GogsRepo, GogsOrg
2+
from gogs_client.entities import GogsUser, GogsRepo, GogsOrg, GogsTeam
33
from gogs_client.interface import GogsApi, ApiFailure, NetworkFailure
44
from gogs_client.updates import GogsUserUpdate, GogsHookUpdate

gogs_client/auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class Authentication(object):
99
An "abstract" parent class. Represents a
1010
means of authenticating oneself to Gogs
1111
"""
12+
1213
def update_kwargs(self, kwargs):
1314
"""
1415
Updates kwargs to include this object's authentication information
@@ -23,6 +24,7 @@ class Token(Authentication):
2324
"""
2425
An immutable representation of a Gogs authentication token
2526
"""
27+
2628
def __init__(self, token, name=None):
2729
"""
2830
:param str token: contents of Gogs authentication token

gogs_client/entities.py

Lines changed: 77 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ def json_get(parsed_json, key):
1515

1616
class GogsUser(object):
1717
"""
18-
An immutable representation of a Gogs user.
18+
An immutable representation of a Gogs user
1919
"""
20+
2021
def __init__(self, user_id, username, full_name, email, avatar_url):
2122
self._id = user_id
2223
self._username = username
@@ -110,7 +111,7 @@ def from_json(parsed_json):
110111
@property # named repo_id to avoid conflict with built-in id
111112
def repo_id(self):
112113
"""
113-
The repository's id number
114+
The repository's id
114115
115116
:rtype: int
116117
"""
@@ -180,6 +181,7 @@ def __init__(self, html_url, clone_url, ssh_url):
180181
def html_url(self):
181182
"""
182183
URL for the repository's webpage
184+
183185
:rtype: str
184186
"""
185187
return self._html_url
@@ -197,7 +199,8 @@ def clone_url(self):
197199
def ssh_url(self):
198200
"""
199201
URL for cloning the repository via SSH
200-
:rtype:
202+
203+
:rtype: str
201204
"""
202205
return self._ssh_url
203206

@@ -256,19 +259,8 @@ def from_json(parsed_json):
256259
events = json_get(parsed_json, "events")
257260
active = json_get(parsed_json, "active")
258261
config = json_get(parsed_json, "config")
259-
260-
return GogsRepo.Hook(hook_id=hook_id, hook_type=hook_type, events=events, active=active,
261-
config=config)
262-
263-
def as_dict(self):
264-
fields = {
265-
"id": self._id,
266-
"type": self._type,
267-
"events": self._events,
268-
"config": self._config,
269-
"active": self._active,
270-
}
271-
return {k: v for (k, v) in fields.items() if v is not None}
262+
return GogsRepo.Hook(hook_id=hook_id, hook_type=hook_type, events=events, active=active,
263+
config=config)
272264

273265
@property # named hook_id to avoid conflict with built-in id
274266
def hook_id(self):
@@ -309,10 +301,7 @@ def active(self):
309301
@property
310302
def config(self):
311303
"""
312-
Config of the hook. Contains max. 3 keys:
313-
- content_type
314-
- url
315-
- secret
304+
Config of the hook. Possible keys include ``"content_type"``, ``"url"``, ``"secret"``
316305
317306
:rtype: dict
318307
"""
@@ -336,19 +325,8 @@ def from_json(parsed_json):
336325
created_at = json_get(parsed_json, "created_at")
337326
read_only = json_get(parsed_json, "read_only")
338327

339-
return GogsRepo.DeployKey(key_id=key_id, key=key, url=url,
340-
title=title, created_at=created_at, read_only=read_only)
341-
342-
def as_dict(self):
343-
fields = {
344-
"id": self._id,
345-
"key": self._key,
346-
"url": self._url,
347-
"title": self._title,
348-
"created_at": self._created_at,
349-
"read_only": self._read_only,
350-
}
351-
return {k: v for (k, v) in fields.items() if v is not None}
328+
return GogsRepo.DeployKey(key_id=key_id, key=key, url=url,
329+
title=title, created_at=created_at, read_only=read_only)
352330

353331
@property # named key_id to avoid conflict with built-in id
354332
def key_id(self):
@@ -371,7 +349,7 @@ def key(self):
371349
@property
372350
def url(self):
373351
"""
374-
Url where the key can be found
352+
URL where the key can be found
375353
376354
:rtype: str
377355
"""
@@ -389,23 +367,27 @@ def title(self):
389367
@property
390368
def created_at(self):
391369
"""
392-
Creation date of the key.
370+
Creation date of the key
371+
393372
:rtype: str
394373
"""
395374
return self._created_at
396375

397376
@property
398377
def read_only(self):
399378
"""
400-
Whether key is read-only.
379+
Whether key is read-only
380+
401381
:rtype: bool
402382
"""
403383
return self._read_only
404384

385+
405386
class GogsOrg(object):
406387
"""
407-
An immutable representation of a Gogs Organization.
388+
An immutable representation of a Gogs Organization
408389
"""
390+
409391
def __init__(self, org_id, username, full_name, avatar_url, description, website, location):
410392
self._id = org_id
411393
self._username = username
@@ -425,20 +407,8 @@ def from_json(parsed_json):
425407
website = json_get(parsed_json, "website")
426408
location = json_get(parsed_json, "location")
427409
return GogsOrg(org_id=org_id, username=username, full_name=full_name,
428-
avatar_url=avatar_url, description=description,
429-
website=website, location=location)
430-
431-
def as_dict(self):
432-
fields = {
433-
"id": self._id,
434-
"username": self._username,
435-
"full_name": self._full_name,
436-
"avatar_url": self._avatar_url,
437-
"description": self._description,
438-
"website": self._website,
439-
"location": self._location
440-
}
441-
return {k: v for (k, v) in fields.items() if v is not None}
410+
avatar_url=avatar_url, description=description,
411+
website=website, location=location)
442412

443413
@property # named org_id to avoid conflict with built-in id
444414
def org_id(self):
@@ -449,7 +419,7 @@ def org_id(self):
449419
"""
450420
return self._id
451421

452-
@property
422+
@property
453423
def username(self):
454424
"""
455425
Organization's username
@@ -458,111 +428,102 @@ def username(self):
458428
"""
459429
return self._username
460430

461-
@property
431+
@property
462432
def full_name(self):
463433
"""
464434
Organization's full name
465435
466436
:rtype: str
467437
"""
468-
return self._full_name
438+
return self._full_name
469439

470-
@property
440+
@property
471441
def avatar_url(self):
472442
"""
473443
Organization's avatar url
474444
475445
:rtype: str
476446
"""
477-
return self._avatar_url
447+
return self._avatar_url
478448

479-
@property
449+
@property
480450
def description(self):
481451
"""
482452
Organization's description
483453
484454
:rtype: str
485455
"""
486-
return self._description
456+
return self._description
487457

488-
@property
458+
@property
489459
def website(self):
490460
"""
491461
Organization's website address
492462
493463
:rtype: str
494464
"""
495-
return self._website
465+
return self._website
496466

497-
@property
467+
@property
498468
def location(self):
499469
"""
500470
Organization's location
501471
502472
:rtype: str
503473
"""
504-
return self._location
474+
return self._location
505475

506-
class Team(object):
507-
"""
508-
Team of an organization
509-
"""
510-
def __init__(self, team_id, name, description, permission):
511-
self._id = team_id
512-
self._name = name
513-
self._description = description
514-
self._permission = permission
515476

516-
@staticmethod
517-
def from_json(parsed_json):
518-
team_id = json_get(parsed_json, "id")
519-
name = json_get(parsed_json, "name")
520-
description = json_get(parsed_json, "description")
521-
permission = json_get(parsed_json, "permission")
522-
return GogsOrg.Team(team_id=team_id, name=name, description=description, permission=permission)
523-
524-
def as_dict(self):
525-
fields = {
526-
"team_id": self._id,
527-
"name": self._name,
528-
"description": self._description,
529-
"permission": self._permission,
530-
}
531-
return {k: v for (k, v) in fields.items() if v is not None}
532-
533-
@property # named team_id to avoid conflict with built-in id
534-
def team_id(self):
535-
"""
536-
Team's id
477+
class GogsTeam(object):
478+
"""
479+
An immutable representation of a Gogs organization team
480+
"""
481+
def __init__(self, team_id, name, description, permission):
482+
self._id = team_id
483+
self._name = name
484+
self._description = description
485+
self._permission = permission
537486

538-
:rtype: int
539-
"""
540-
return self._id
487+
@staticmethod
488+
def from_json(parsed_json):
489+
team_id = json_get(parsed_json, "id")
490+
name = json_get(parsed_json, "name")
491+
description = json_get(parsed_json, "description")
492+
permission = json_get(parsed_json, "permission")
493+
return GogsTeam(team_id=team_id, name=name, description=description, permission=permission)
541494

542-
@property
543-
def name(self):
544-
"""
545-
Team name
495+
@property # named team_id to avoid conflict with built-in id
496+
def team_id(self):
497+
"""
498+
Team's id
546499
547-
:rtype: str
548-
"""
549-
return self._name
500+
:rtype: int
501+
"""
502+
return self._id
550503

551-
@property
552-
def description(self):
553-
"""
554-
Description to the team
504+
@property
505+
def name(self):
506+
"""
507+
Team name
555508
556-
:rtype: str
557-
"""
558-
return self._description
509+
:rtype: str
510+
"""
511+
return self._name
559512

560-
@property
561-
def permission(self):
562-
"""
563-
Team permission, can be read, write or admin, default is read
513+
@property
514+
def description(self):
515+
"""
516+
Description of the team
564517
565-
:rtype: int
566-
"""
567-
return self._permission
518+
:rtype: str
519+
"""
520+
return self._description
568521

522+
@property
523+
def permission(self):
524+
"""
525+
Team permission, can be read, write or admin, default is read
526+
527+
:rtype: int
528+
"""
529+
return self._permission

0 commit comments

Comments
 (0)