@@ -13,17 +13,24 @@ 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
+
21
+ class GogsUser (GogsEntity ):
17
22
"""
18
23
An immutable representation of a Gogs user
19
24
"""
20
25
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 )
22
28
self ._id = user_id
23
29
self ._username = username
24
30
self ._full_name = full_name
25
31
self ._email = email
26
32
self ._avatar_url = avatar_url
33
+ self ._json = json
27
34
28
35
@staticmethod
29
36
def from_json (parsed_json ):
@@ -33,7 +40,7 @@ def from_json(parsed_json):
33
40
email = parsed_json .get ("email" , None )
34
41
avatar_url = parsed_json .get ("avatar_url" , None )
35
42
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 )
37
44
38
45
@property # named user_id to avoid conflict with built-in id
39
46
def user_id (self ):
@@ -81,17 +88,20 @@ def avatar_url(self):
81
88
return self ._avatar_url
82
89
83
90
84
- class GogsRepo (object ):
91
+ class GogsRepo (GogsEntity ):
85
92
"""
86
93
An immutable representation of a Gogs repository
87
94
"""
88
95
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 )
90
99
self ._repo_id = repo_id
91
100
self ._owner = owner
92
101
self ._full_name = full_name
93
102
self ._private = private
94
103
self ._fork = fork
104
+ self ._default_branch = default_branch
95
105
self ._urls = urls
96
106
self ._permissions = permissions
97
107
@@ -102,11 +112,12 @@ def from_json(parsed_json):
102
112
full_name = json_get (parsed_json , "full_name" )
103
113
private = json_get (parsed_json , "private" )
104
114
fork = json_get (parsed_json , "fork" )
115
+ default_branch = json_get (parsed_json , "default_branch" )
105
116
urls = GogsRepo .Urls (json_get (parsed_json , "html_url" ), json_get (parsed_json , "clone_url" ),
106
117
json_get (parsed_json , "ssh_url" ))
107
118
permissions = GogsRepo .Permissions .from_json (json_get (parsed_json , "permissions" ))
108
119
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 )
110
121
111
122
@property # named repo_id to avoid conflict with built-in id
112
123
def repo_id (self ):
@@ -153,6 +164,15 @@ def fork(self):
153
164
"""
154
165
return self ._fork
155
166
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
+
156
176
@property
157
177
def urls (self ):
158
178
"""
@@ -204,8 +224,9 @@ def ssh_url(self):
204
224
"""
205
225
return self ._ssh_url
206
226
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 )
209
230
self ._admin = admin
210
231
self ._push = push
211
232
self ._pull = pull
@@ -215,7 +236,7 @@ def from_json(parsed_json):
215
236
admin = parsed_json .get ("admin" , False )
216
237
push = parsed_json .get ("push" , False )
217
238
pull = parsed_json .get ("pull" , False )
218
- return GogsRepo .Permissions (admin , push , pull )
239
+ return GogsRepo .Permissions (admin , push , pull , parsed_json )
219
240
220
241
@property
221
242
def admin (self ):
@@ -244,8 +265,9 @@ def pull(self):
244
265
"""
245
266
return self ._pull
246
267
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 )
249
271
self ._id = hook_id
250
272
self ._type = hook_type
251
273
self ._events = events
@@ -260,7 +282,7 @@ def from_json(parsed_json):
260
282
active = json_get (parsed_json , "active" )
261
283
config = json_get (parsed_json , "config" )
262
284
return GogsRepo .Hook (hook_id = hook_id , hook_type = hook_type , events = events , active = active ,
263
- config = config )
285
+ config = config , json = parsed_json )
264
286
265
287
@property # named hook_id to avoid conflict with built-in id
266
288
def hook_id (self ):
@@ -307,8 +329,9 @@ def config(self):
307
329
"""
308
330
return self ._config
309
331
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 )
312
335
self ._id = key_id
313
336
self ._key = key
314
337
self ._url = url
@@ -326,7 +349,8 @@ def from_json(parsed_json):
326
349
read_only = json_get (parsed_json , "read_only" )
327
350
328
351
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 )
330
354
331
355
@property # named key_id to avoid conflict with built-in id
332
356
def key_id (self ):
@@ -383,12 +407,13 @@ def read_only(self):
383
407
return self ._read_only
384
408
385
409
386
- class GogsOrg (object ):
410
+ class GogsOrg (GogsEntity ):
387
411
"""
388
412
An immutable representation of a Gogs Organization
389
413
"""
390
414
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 (GogsOrg , self ).__init__ (json = json )
392
417
self ._id = org_id
393
418
self ._username = username
394
419
self ._full_name = full_name
@@ -408,7 +433,7 @@ def from_json(parsed_json):
408
433
location = json_get (parsed_json , "location" )
409
434
return GogsOrg (org_id = org_id , username = username , full_name = full_name ,
410
435
avatar_url = avatar_url , description = description ,
411
- website = website , location = location )
436
+ website = website , location = location , json = parsed_json )
412
437
413
438
@property # named org_id to avoid conflict with built-in id
414
439
def org_id (self ):
@@ -474,11 +499,12 @@ def location(self):
474
499
return self ._location
475
500
476
501
477
- class GogsTeam (object ):
502
+ class GogsTeam (GogsEntity ):
478
503
"""
479
504
An immutable representation of a Gogs organization team
480
505
"""
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 )
482
508
self ._id = team_id
483
509
self ._name = name
484
510
self ._description = description
@@ -490,7 +516,8 @@ def from_json(parsed_json):
490
516
name = json_get (parsed_json , "name" )
491
517
description = json_get (parsed_json , "description" )
492
518
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 )
494
521
495
522
@property # named team_id to avoid conflict with built-in id
496
523
def team_id (self ):
0 commit comments