@@ -13,12 +13,21 @@ def json_get(parsed_json, key):
1313 return parsed_json [key ]
1414
1515
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 ):
1725 """
1826 An immutable representation of a Gogs user
1927 """
2028
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 )
2231 self ._id = user_id
2332 self ._username = username
2433 self ._full_name = full_name
@@ -33,7 +42,7 @@ def from_json(parsed_json):
3342 email = parsed_json .get ("email" , None )
3443 avatar_url = parsed_json .get ("avatar_url" , None )
3544 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 )
3746
3847 @property # named user_id to avoid conflict with built-in id
3948 def user_id (self ):
@@ -81,17 +90,22 @@ def avatar_url(self):
8190 return self ._avatar_url
8291
8392
84- class GogsRepo (object ):
93+ class GogsRepo (GogsEntity ):
8594 """
8695 An immutable representation of a Gogs repository
8796 """
8897
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 )
90101 self ._repo_id = repo_id
91102 self ._owner = owner
92103 self ._full_name = full_name
93104 self ._private = private
94105 self ._fork = fork
106+ self ._default_branch = default_branch
107+ self ._empty = empty
108+ self ._size = size
95109 self ._urls = urls
96110 self ._permissions = permissions
97111
@@ -102,11 +116,15 @@ def from_json(parsed_json):
102116 full_name = json_get (parsed_json , "full_name" )
103117 private = json_get (parsed_json , "private" )
104118 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 )
105122 urls = GogsRepo .Urls (json_get (parsed_json , "html_url" ), json_get (parsed_json , "clone_url" ),
106123 json_get (parsed_json , "ssh_url" ))
107124 permissions = GogsRepo .Permissions .from_json (json_get (parsed_json , "permissions" ))
108125 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 )
110128
111129 @property # named repo_id to avoid conflict with built-in id
112130 def repo_id (self ):
@@ -153,6 +171,33 @@ def fork(self):
153171 """
154172 return self ._fork
155173
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+
156201 @property
157202 def urls (self ):
158203 """
@@ -204,8 +249,9 @@ def ssh_url(self):
204249 """
205250 return self ._ssh_url
206251
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 )
209255 self ._admin = admin
210256 self ._push = push
211257 self ._pull = pull
@@ -215,7 +261,7 @@ def from_json(parsed_json):
215261 admin = parsed_json .get ("admin" , False )
216262 push = parsed_json .get ("push" , False )
217263 pull = parsed_json .get ("pull" , False )
218- return GogsRepo .Permissions (admin , push , pull )
264+ return GogsRepo .Permissions (admin , push , pull , parsed_json )
219265
220266 @property
221267 def admin (self ):
@@ -244,8 +290,9 @@ def pull(self):
244290 """
245291 return self ._pull
246292
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 )
249296 self ._id = hook_id
250297 self ._type = hook_type
251298 self ._events = events
@@ -260,7 +307,7 @@ def from_json(parsed_json):
260307 active = json_get (parsed_json , "active" )
261308 config = json_get (parsed_json , "config" )
262309 return GogsRepo .Hook (hook_id = hook_id , hook_type = hook_type , events = events , active = active ,
263- config = config )
310+ config = config , json = parsed_json )
264311
265312 @property # named hook_id to avoid conflict with built-in id
266313 def hook_id (self ):
@@ -307,8 +354,9 @@ def config(self):
307354 """
308355 return self ._config
309356
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 )
312360 self ._id = key_id
313361 self ._key = key
314362 self ._url = url
@@ -326,7 +374,8 @@ def from_json(parsed_json):
326374 read_only = json_get (parsed_json , "read_only" )
327375
328376 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 )
330379
331380 @property # named key_id to avoid conflict with built-in id
332381 def key_id (self ):
@@ -383,12 +432,13 @@ def read_only(self):
383432 return self ._read_only
384433
385434
386- class GogsOrg (object ):
435+ class GogsOrg (GogsEntity ):
387436 """
388437 An immutable representation of a Gogs Organization
389438 """
390439
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 )
392442 self ._id = org_id
393443 self ._username = username
394444 self ._full_name = full_name
@@ -408,7 +458,7 @@ def from_json(parsed_json):
408458 location = json_get (parsed_json , "location" )
409459 return GogsOrg (org_id = org_id , username = username , full_name = full_name ,
410460 avatar_url = avatar_url , description = description ,
411- website = website , location = location )
461+ website = website , location = location , json = parsed_json )
412462
413463 @property # named org_id to avoid conflict with built-in id
414464 def org_id (self ):
@@ -474,11 +524,12 @@ def location(self):
474524 return self ._location
475525
476526
477- class GogsTeam (object ):
527+ class GogsTeam (GogsEntity ):
478528 """
479529 An immutable representation of a Gogs organization team
480530 """
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 )
482533 self ._id = team_id
483534 self ._name = name
484535 self ._description = description
@@ -490,7 +541,8 @@ def from_json(parsed_json):
490541 name = json_get (parsed_json , "name" )
491542 description = json_get (parsed_json , "description" )
492543 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 )
494546
495547 @property # named team_id to avoid conflict with built-in id
496548 def team_id (self ):
0 commit comments