2
2
Various immutable classes that represent Gogs entities.
3
3
"""
4
4
5
+ from collections import OrderedDict
6
+
7
+ import attr
8
+
5
9
6
10
def json_get (parsed_json , key ):
7
11
"""
@@ -12,13 +16,11 @@ def json_get(parsed_json, key):
12
16
raise ValueError ("JSON does not contain a {} field" .format (key ))
13
17
return parsed_json [key ]
14
18
15
- import attr
16
-
17
- from collections import OrderedDict
18
19
19
20
@attr .s
20
21
class GogsEntity (object ):
21
22
json = attr .ib ()
23
+
22
24
@classmethod
23
25
def from_json (cls , parsed_json ):
24
26
# with introspection, get arguments of the constructor
@@ -44,40 +46,31 @@ class GogsUser(GogsEntity):
44
46
An immutable representation of a Gogs user
45
47
"""
46
48
47
- """
48
- The user's id
49
-
50
- :rtype: int
51
- """
49
+ #: The user's id
50
+ #:
51
+ #: :rtype: int
52
52
id = attr .ib ()
53
- user_id = property (lambda self : self .id )
54
53
55
- """
56
- The user's username
54
+ user_id = property (lambda self : self .id )
57
55
58
- :rtype: str
59
- """
56
+ #: The user's username
57
+ #:
58
+ #: :rtype: str
60
59
username = attr .ib ()
61
60
62
- """
63
- The user's full name
64
-
65
- :rtype: str
66
- """
61
+ #: The user's full name
62
+ #:
63
+ #: :rtype: str
67
64
full_name = attr .ib ()
68
65
69
- """
70
- The user's email address. Can be empty as a result of invalid authentication
71
-
72
- :rtype: str
73
- """
66
+ #: The user's email address. Can be empty as a result of invalid authentication
67
+ #:
68
+ #: :rtype: str
74
69
email = attr .ib (default = None )
75
70
76
- """
77
- The user's avatar URL
78
-
79
- :rtype: str
80
- """
71
+ #: The user's avatar URL
72
+ #:
73
+ #: :rtype: str
81
74
avatar_url = attr .ib (default = None )
82
75
83
76
@@ -100,7 +93,7 @@ class GogsRepo(GogsEntity):
100
93
101
94
:rtype: entities.GogsUser
102
95
"""
103
- owner = attr .ib (convert = lambda parsed_json :GogsUser .from_json (parsed_json ))
96
+ owner = attr .ib (convert = lambda parsed_json : GogsUser .from_json (parsed_json ))
104
97
105
98
"""
106
99
The full name of the repository
@@ -130,31 +123,30 @@ class GogsRepo(GogsEntity):
130
123
"""
131
124
default_branch = attr .ib ()
132
125
133
- """
134
- URLs of the repository
135
-
136
- :rtype: GogsRepo.Urls
137
- """
138
- _ssh_url = attr .ib ()
139
126
_html_url = attr .ib ()
140
127
_clone_url = attr .ib ()
128
+ _ssh_url = attr .ib ()
129
+
130
+ #: URLs of the repository
131
+ #:
132
+ #: :rtype: GogsRepo.Urls
141
133
@property
142
134
def urls (self ):
143
- return GogsRepo .Urls (self ._html_url , self ._clone_url ,self ._ssh_url )
135
+ return GogsRepo .Urls (self ._html_url , self ._clone_url , self ._ssh_url )
144
136
145
137
"""
146
138
Permissions for the repository
147
139
148
140
:rtype: GogsRepo.Permissions
149
141
"""
150
- permissions = attr .ib (convert = lambda data :GogsRepo .Permissions .from_json (data ))
142
+ permissions = attr .ib (convert = lambda data : GogsRepo .Permissions .from_json (data ))
151
143
152
144
"""
153
145
Gets the repository's parent, when a fork
154
146
155
147
:rtype: GogsRepo
156
148
"""
157
- parent = attr .ib (convert = lambda data :GogsRepo .from_json (data ) if data else None , default = None )
149
+ parent = attr .ib (convert = lambda data : GogsRepo .from_json (data ) if data else None , default = None )
158
150
159
151
"""
160
152
Whether the repository is empty
@@ -357,6 +349,7 @@ class GogsOrg(GogsEntity):
357
349
"""
358
350
location = attr .ib ()
359
351
352
+
360
353
@attr .s (frozen = True )
361
354
class GogsTeam (GogsEntity ):
362
355
"""
@@ -391,4 +384,3 @@ class GogsTeam(GogsEntity):
391
384
:rtype: int
392
385
"""
393
386
permission = attr .ib ()
394
-
0 commit comments