@@ -13,17 +13,24 @@ 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+
21+ class GogsUser (GogsEntity ):
1722 """
1823 An immutable representation of a Gogs user
1924 """
2025
21- def __init__ (self , user_id , username , full_name , email , avatar_url ):
26+ def __init__ (self , user_id , username , full_name , email , avatar_url , json = {}):
27+ super (GogsUser , self ).__init__ (json = json )
2228 self ._id = user_id
2329 self ._username = username
2430 self ._full_name = full_name
2531 self ._email = email
2632 self ._avatar_url = avatar_url
33+ self ._json = json
2734
2835 @staticmethod
2936 def from_json (parsed_json ):
@@ -33,7 +40,7 @@ def from_json(parsed_json):
3340 email = parsed_json .get ("email" , None )
3441 avatar_url = parsed_json .get ("avatar_url" , None )
3542 return GogsUser (user_id = user_id , username = username , full_name = full_name ,
36- email = email , avatar_url = avatar_url )
43+ email = email , avatar_url = avatar_url , json = parsed_json )
3744
3845 @property # named user_id to avoid conflict with built-in id
3946 def user_id (self ):
@@ -81,17 +88,20 @@ def avatar_url(self):
8188 return self ._avatar_url
8289
8390
84- class GogsRepo (object ):
91+ class GogsRepo (GogsEntity ):
8592 """
8693 An immutable representation of a Gogs repository
8794 """
8895
89- def __init__ (self , repo_id , owner , full_name , private , fork , urls , permissions ):
96+ def __init__ (self , repo_id , owner , full_name , private , fork , default_branch ,
97+ urls , permissions , json = {}):
98+ super (GogsRepo , self ).__init__ (json = json )
9099 self ._repo_id = repo_id
91100 self ._owner = owner
92101 self ._full_name = full_name
93102 self ._private = private
94103 self ._fork = fork
104+ self ._default_branch = default_branch
95105 self ._urls = urls
96106 self ._permissions = permissions
97107
@@ -102,11 +112,12 @@ def from_json(parsed_json):
102112 full_name = json_get (parsed_json , "full_name" )
103113 private = json_get (parsed_json , "private" )
104114 fork = json_get (parsed_json , "fork" )
115+ default_branch = json_get (parsed_json , "default_branch" )
105116 urls = GogsRepo .Urls (json_get (parsed_json , "html_url" ), json_get (parsed_json , "clone_url" ),
106117 json_get (parsed_json , "ssh_url" ))
107118 permissions = GogsRepo .Permissions .from_json (json_get (parsed_json , "permissions" ))
108119 return GogsRepo (repo_id = repo_id , owner = owner , full_name = full_name , private = private , fork = fork ,
109- urls = urls , permissions = permissions )
120+ default_branch = default_branch , urls = urls , permissions = permissions , json = parsed_json )
110121
111122 @property # named repo_id to avoid conflict with built-in id
112123 def repo_id (self ):
@@ -153,6 +164,15 @@ def fork(self):
153164 """
154165 return self ._fork
155166
167+ @property
168+ def default_branch (self ):
169+ """
170+ The name of the default branch
171+
172+ :rtype: bool
173+ """
174+ return self ._default_branch
175+
156176 @property
157177 def urls (self ):
158178 """
@@ -204,8 +224,9 @@ def ssh_url(self):
204224 """
205225 return self ._ssh_url
206226
207- class Permissions (object ):
208- def __init__ (self , admin , push , pull ):
227+ class Permissions (GogsEntity ):
228+ def __init__ (self , admin , push , pull , json = {}):
229+ super (GogsRepo .Permissions , self ).__init__ (json = json )
209230 self ._admin = admin
210231 self ._push = push
211232 self ._pull = pull
@@ -215,7 +236,7 @@ def from_json(parsed_json):
215236 admin = parsed_json .get ("admin" , False )
216237 push = parsed_json .get ("push" , False )
217238 pull = parsed_json .get ("pull" , False )
218- return GogsRepo .Permissions (admin , push , pull )
239+ return GogsRepo .Permissions (admin , push , pull , parsed_json )
219240
220241 @property
221242 def admin (self ):
@@ -244,8 +265,9 @@ def pull(self):
244265 """
245266 return self ._pull
246267
247- class Hook (object ):
248- def __init__ (self , hook_id , hook_type , events , active , config ):
268+ class Hook (GogsEntity ):
269+ def __init__ (self , hook_id , hook_type , events , active , config , json = {}):
270+ super (GogsRepo .Hook , self ).__init__ (json = json )
249271 self ._id = hook_id
250272 self ._type = hook_type
251273 self ._events = events
@@ -260,7 +282,7 @@ def from_json(parsed_json):
260282 active = json_get (parsed_json , "active" )
261283 config = json_get (parsed_json , "config" )
262284 return GogsRepo .Hook (hook_id = hook_id , hook_type = hook_type , events = events , active = active ,
263- config = config )
285+ config = config , json = parsed_json )
264286
265287 @property # named hook_id to avoid conflict with built-in id
266288 def hook_id (self ):
@@ -307,8 +329,9 @@ def config(self):
307329 """
308330 return self ._config
309331
310- class DeployKey (object ):
311- def __init__ (self , key_id , key , url , title , created_at , read_only ):
332+ class DeployKey (GogsEntity ):
333+ def __init__ (self , key_id , key , url , title , created_at , read_only , json = {}):
334+ super (GogsRepo .DeployKey , self ).__init__ (json = json )
312335 self ._id = key_id
313336 self ._key = key
314337 self ._url = url
@@ -326,7 +349,8 @@ def from_json(parsed_json):
326349 read_only = json_get (parsed_json , "read_only" )
327350
328351 return GogsRepo .DeployKey (key_id = key_id , key = key , url = url ,
329- title = title , created_at = created_at , read_only = read_only )
352+ title = title , created_at = created_at ,
353+ read_only = read_only , json = parsed_json )
330354
331355 @property # named key_id to avoid conflict with built-in id
332356 def key_id (self ):
@@ -383,12 +407,13 @@ def read_only(self):
383407 return self ._read_only
384408
385409
386- class GogsOrg (object ):
410+ class GogsOrg (GogsEntity ):
387411 """
388412 An immutable representation of a Gogs Organization
389413 """
390414
391- def __init__ (self , org_id , username , full_name , avatar_url , description , website , location ):
415+ def __init__ (self , org_id , username , full_name , avatar_url , description , website , location , json = {}):
416+ super (GogsRepo .GogsOrg , self ).__init__ (json = json )
392417 self ._id = org_id
393418 self ._username = username
394419 self ._full_name = full_name
@@ -408,7 +433,7 @@ def from_json(parsed_json):
408433 location = json_get (parsed_json , "location" )
409434 return GogsOrg (org_id = org_id , username = username , full_name = full_name ,
410435 avatar_url = avatar_url , description = description ,
411- website = website , location = location )
436+ website = website , location = location , json = parsed_json )
412437
413438 @property # named org_id to avoid conflict with built-in id
414439 def org_id (self ):
@@ -474,11 +499,12 @@ def location(self):
474499 return self ._location
475500
476501
477- class GogsTeam (object ):
502+ class GogsTeam (GogsEntity ):
478503 """
479504 An immutable representation of a Gogs organization team
480505 """
481- def __init__ (self , team_id , name , description , permission ):
506+ def __init__ (self , team_id , name , description , permission , json = {}):
507+ super (GogsTeam , self ).__init__ (json = json )
482508 self ._id = team_id
483509 self ._name = name
484510 self ._description = description
@@ -490,7 +516,8 @@ def from_json(parsed_json):
490516 name = json_get (parsed_json , "name" )
491517 description = json_get (parsed_json , "description" )
492518 permission = json_get (parsed_json , "permission" )
493- return GogsTeam (team_id = team_id , name = name , description = description , permission = permission )
519+ return GogsTeam (team_id = team_id , name = name , description = description ,
520+ permission = permission , json = parsed_json )
494521
495522 @property # named team_id to avoid conflict with built-in id
496523 def team_id (self ):
0 commit comments