@@ -13,12 +13,21 @@ def json_get(parsed_json, key):
13
13
return parsed_json [key ]
14
14
15
15
16
- class GogsUser (object ):
16
+ class GogsEntity (object ):
17
+ def __init__ (self , json ):
18
+ self ._json = json
19
+
20
+ @property
21
+ def json (self ):
22
+ return self ._json
23
+
24
+ class GogsUser (GogsEntity ):
17
25
"""
18
26
An immutable representation of a Gogs user
19
27
"""
20
28
21
- def __init__ (self , user_id , username , full_name , email , avatar_url ):
29
+ def __init__ (self , user_id , username , full_name , email , avatar_url , json = {}):
30
+ super (GogsUser , self ).__init__ (json = json )
22
31
self ._id = user_id
23
32
self ._username = username
24
33
self ._full_name = full_name
@@ -33,7 +42,7 @@ def from_json(parsed_json):
33
42
email = parsed_json .get ("email" , None )
34
43
avatar_url = parsed_json .get ("avatar_url" , None )
35
44
return GogsUser (user_id = user_id , username = username , full_name = full_name ,
36
- email = email , avatar_url = avatar_url )
45
+ email = email , avatar_url = avatar_url , json = parsed_json )
37
46
38
47
@property # named user_id to avoid conflict with built-in id
39
48
def user_id (self ):
@@ -81,17 +90,22 @@ def avatar_url(self):
81
90
return self ._avatar_url
82
91
83
92
84
- class GogsRepo (object ):
93
+ class GogsRepo (GogsEntity ):
85
94
"""
86
95
An immutable representation of a Gogs repository
87
96
"""
88
97
89
- def __init__ (self , repo_id , owner , full_name , private , fork , urls , permissions ):
98
+ def __init__ (self , repo_id , owner , full_name , private , fork , default_branch ,
99
+ empty , size , urls , permissions , json = {}):
100
+ super (GogsRepo , self ).__init__ (json = json )
90
101
self ._repo_id = repo_id
91
102
self ._owner = owner
92
103
self ._full_name = full_name
93
104
self ._private = private
94
105
self ._fork = fork
106
+ self ._default_branch = default_branch
107
+ self ._empty = empty
108
+ self ._size = size
95
109
self ._urls = urls
96
110
self ._permissions = permissions
97
111
@@ -102,11 +116,15 @@ def from_json(parsed_json):
102
116
full_name = json_get (parsed_json , "full_name" )
103
117
private = json_get (parsed_json , "private" )
104
118
fork = json_get (parsed_json , "fork" )
119
+ default_branch = json_get (parsed_json , "default_branch" )
120
+ empty = parsed_json .get ("empty" , None )
121
+ size = parsed_json .get ("size" , None )
105
122
urls = GogsRepo .Urls (json_get (parsed_json , "html_url" ), json_get (parsed_json , "clone_url" ),
106
123
json_get (parsed_json , "ssh_url" ))
107
124
permissions = GogsRepo .Permissions .from_json (json_get (parsed_json , "permissions" ))
108
125
return GogsRepo (repo_id = repo_id , owner = owner , full_name = full_name , private = private , fork = fork ,
109
- urls = urls , permissions = permissions )
126
+ default_branch = default_branch , empty = empty , size = size , urls = urls ,
127
+ permissions = permissions , json = parsed_json )
110
128
111
129
@property # named repo_id to avoid conflict with built-in id
112
130
def repo_id (self ):
@@ -153,6 +171,33 @@ def fork(self):
153
171
"""
154
172
return self ._fork
155
173
174
+ @property
175
+ def default_branch (self ):
176
+ """
177
+ The name of the default branch
178
+
179
+ :rtype: str
180
+ """
181
+ return self ._default_branch
182
+
183
+ @property
184
+ def empty (self ):
185
+ """
186
+ Whether the repository is empty
187
+
188
+ :rtype: bool
189
+ """
190
+ return self ._empty
191
+
192
+ @property
193
+ def size (self ):
194
+ """
195
+ Size of the repository in kilobytes
196
+
197
+ :rtype: int
198
+ """
199
+ return self ._size
200
+
156
201
@property
157
202
def urls (self ):
158
203
"""
@@ -204,8 +249,9 @@ def ssh_url(self):
204
249
"""
205
250
return self ._ssh_url
206
251
207
- class Permissions (object ):
208
- def __init__ (self , admin , push , pull ):
252
+ class Permissions (GogsEntity ):
253
+ def __init__ (self , admin , push , pull , json = {}):
254
+ super (GogsRepo .Permissions , self ).__init__ (json = json )
209
255
self ._admin = admin
210
256
self ._push = push
211
257
self ._pull = pull
@@ -215,7 +261,7 @@ def from_json(parsed_json):
215
261
admin = parsed_json .get ("admin" , False )
216
262
push = parsed_json .get ("push" , False )
217
263
pull = parsed_json .get ("pull" , False )
218
- return GogsRepo .Permissions (admin , push , pull )
264
+ return GogsRepo .Permissions (admin , push , pull , parsed_json )
219
265
220
266
@property
221
267
def admin (self ):
@@ -244,8 +290,9 @@ def pull(self):
244
290
"""
245
291
return self ._pull
246
292
247
- class Hook (object ):
248
- def __init__ (self , hook_id , hook_type , events , active , config ):
293
+ class Hook (GogsEntity ):
294
+ def __init__ (self , hook_id , hook_type , events , active , config , json = {}):
295
+ super (GogsRepo .Hook , self ).__init__ (json = json )
249
296
self ._id = hook_id
250
297
self ._type = hook_type
251
298
self ._events = events
@@ -260,7 +307,7 @@ def from_json(parsed_json):
260
307
active = json_get (parsed_json , "active" )
261
308
config = json_get (parsed_json , "config" )
262
309
return GogsRepo .Hook (hook_id = hook_id , hook_type = hook_type , events = events , active = active ,
263
- config = config )
310
+ config = config , json = parsed_json )
264
311
265
312
@property # named hook_id to avoid conflict with built-in id
266
313
def hook_id (self ):
@@ -307,8 +354,9 @@ def config(self):
307
354
"""
308
355
return self ._config
309
356
310
- class DeployKey (object ):
311
- def __init__ (self , key_id , key , url , title , created_at , read_only ):
357
+ class DeployKey (GogsEntity ):
358
+ def __init__ (self , key_id , key , url , title , created_at , read_only , json = {}):
359
+ super (GogsRepo .DeployKey , self ).__init__ (json = json )
312
360
self ._id = key_id
313
361
self ._key = key
314
362
self ._url = url
@@ -326,7 +374,8 @@ def from_json(parsed_json):
326
374
read_only = json_get (parsed_json , "read_only" )
327
375
328
376
return GogsRepo .DeployKey (key_id = key_id , key = key , url = url ,
329
- title = title , created_at = created_at , read_only = read_only )
377
+ title = title , created_at = created_at ,
378
+ read_only = read_only , json = parsed_json )
330
379
331
380
@property # named key_id to avoid conflict with built-in id
332
381
def key_id (self ):
@@ -383,12 +432,13 @@ def read_only(self):
383
432
return self ._read_only
384
433
385
434
386
- class GogsOrg (object ):
435
+ class GogsOrg (GogsEntity ):
387
436
"""
388
437
An immutable representation of a Gogs Organization
389
438
"""
390
439
391
- def __init__ (self , org_id , username , full_name , avatar_url , description , website , location ):
440
+ def __init__ (self , org_id , username , full_name , avatar_url , description , website , location , json = {}):
441
+ super (GogsOrg , self ).__init__ (json = json )
392
442
self ._id = org_id
393
443
self ._username = username
394
444
self ._full_name = full_name
@@ -408,7 +458,7 @@ def from_json(parsed_json):
408
458
location = json_get (parsed_json , "location" )
409
459
return GogsOrg (org_id = org_id , username = username , full_name = full_name ,
410
460
avatar_url = avatar_url , description = description ,
411
- website = website , location = location )
461
+ website = website , location = location , json = parsed_json )
412
462
413
463
@property # named org_id to avoid conflict with built-in id
414
464
def org_id (self ):
@@ -474,11 +524,12 @@ def location(self):
474
524
return self ._location
475
525
476
526
477
- class GogsTeam (object ):
527
+ class GogsTeam (GogsEntity ):
478
528
"""
479
529
An immutable representation of a Gogs organization team
480
530
"""
481
- def __init__ (self , team_id , name , description , permission ):
531
+ def __init__ (self , team_id , name , description , permission , json = {}):
532
+ super (GogsTeam , self ).__init__ (json = json )
482
533
self ._id = team_id
483
534
self ._name = name
484
535
self ._description = description
@@ -490,7 +541,8 @@ def from_json(parsed_json):
490
541
name = json_get (parsed_json , "name" )
491
542
description = json_get (parsed_json , "description" )
492
543
permission = json_get (parsed_json , "permission" )
493
- return GogsTeam (team_id = team_id , name = name , description = description , permission = permission )
544
+ return GogsTeam (team_id = team_id , name = name , description = description ,
545
+ permission = permission , json = parsed_json )
494
546
495
547
@property # named team_id to avoid conflict with built-in id
496
548
def team_id (self ):
0 commit comments