@@ -240,3 +240,329 @@ def pull(self):
240240 :rtype: bool
241241 """
242242 return self ._pull
243+
244+ class Hook (object ):
245+ def __init__ (self , hook_id , hook_type , events , active , config ):
246+ self ._id = hook_id
247+ self ._type = hook_type
248+ self ._events = events
249+ self ._active = active
250+ self ._config = config
251+
252+ @staticmethod
253+ def from_json (parsed_json ):
254+ hook_id = json_get (parsed_json , "id" )
255+ hook_type = json_get (parsed_json , "type" )
256+ events = json_get (parsed_json , "events" )
257+ active = json_get (parsed_json , "active" )
258+ config = json_get (parsed_json , "config" )
259+
260+ return GogsRepo .Hook (hook_id = hook_id , hook_type = hook_type , events = events , active = active ,
261+ config = config )
262+
263+ def as_dict (self ):
264+ fields = {
265+ "id" : self ._id ,
266+ "type" : self ._type ,
267+ "events" : self ._events ,
268+ "config" : self ._config ,
269+ "active" : self ._active ,
270+ }
271+ return {k : v for (k , v ) in fields .items () if v is not None }
272+
273+ @property # named hook_id to avoid conflict with built-in id
274+ def hook_id (self ):
275+ """
276+ The hook's id number
277+
278+ :rtype: int
279+ """
280+ return self ._id
281+
282+ @property # named hook_type to avoid conflict with built-in type
283+ def hook_type (self ):
284+ """
285+ The hook's type (gogs, slack, etc.)
286+
287+ :rtype: str
288+ """
289+ return self ._type
290+
291+ @property
292+ def events (self ):
293+ """
294+ The events that fire the hook
295+
296+ :rtype: List[str]
297+ """
298+ return self ._events
299+
300+ @property
301+ def active (self ):
302+ """
303+ Whether the hook is active
304+
305+ :rtype: bool
306+ """
307+ return self ._active
308+
309+ @property
310+ def config (self ):
311+ """
312+ Config of the hook. Contains max. 3 keys:
313+ - content_type
314+ - url
315+ - secret
316+
317+ :rtype: dict
318+ """
319+ return self ._config
320+
321+ class DeployKey (object ):
322+ def __init__ (self , key_id , key , url , title , created_at , read_only ):
323+ self ._id = key_id
324+ self ._key = key
325+ self ._url = url
326+ self ._title = title
327+ self ._created_at = created_at
328+ self ._read_only = read_only
329+
330+ @staticmethod
331+ def from_json (parsed_json ):
332+ key_id = json_get (parsed_json , "id" )
333+ key = json_get (parsed_json , "key" )
334+ url = json_get (parsed_json , "url" )
335+ title = json_get (parsed_json , "title" )
336+ created_at = json_get (parsed_json , "created_at" )
337+ read_only = json_get (parsed_json , "read_only" )
338+
339+ return GogsRepo .DeployKey (key_id = key_id , key = key , url = url ,
340+ title = title , created_at = created_at , read_only = read_only )
341+
342+ def as_dict (self ):
343+ fields = {
344+ "id" : self ._id ,
345+ "key" : self ._key ,
346+ "url" : self ._url ,
347+ "title" : self ._title ,
348+ "created_at" : self ._created_at ,
349+ "read_only" : self ._read_only ,
350+ }
351+ return {k : v for (k , v ) in fields .items () if v is not None }
352+
353+ @property # named key_id to avoid conflict with built-in id
354+ def key_id (self ):
355+ """
356+ The key's id number
357+
358+ :rtype: int
359+ """
360+ return self ._id
361+
362+ @property
363+ def key (self ):
364+ """
365+ The content of the key
366+
367+ :rtype: str
368+ """
369+ return self ._key
370+
371+ @property
372+ def url (self ):
373+ """
374+ Url where the key can be found
375+
376+ :rtype: str
377+ """
378+ return self ._url
379+
380+ @property
381+ def title (self ):
382+ """
383+ The name of the key
384+
385+ :rtype: str
386+ """
387+ return self ._title
388+
389+ @property
390+ def created_at (self ):
391+ """
392+ Creation date of the key.
393+ :rtype: str
394+ """
395+ return self ._created_at
396+
397+ @property
398+ def read_only (self ):
399+ """
400+ Whether key is read-only.
401+ :rtype: bool
402+ """
403+ return self ._read_only
404+
405+ class GogsOrg (object ):
406+ """
407+ An immutable representation of a Gogs Organization.
408+ """
409+ def __init__ (self , org_id , username , full_name , avatar_url , description , website , location ):
410+ self ._id = org_id
411+ self ._username = username
412+ self ._full_name = full_name
413+ self ._avatar_url = avatar_url
414+ self ._description = description
415+ self ._website = website
416+ self ._location = location
417+
418+ @staticmethod
419+ def from_json (parsed_json ):
420+ org_id = json_get (parsed_json , "id" )
421+ username = json_get (parsed_json , "username" )
422+ full_name = json_get (parsed_json , "full_name" )
423+ avatar_url = json_get (parsed_json , "avatar_url" )
424+ description = json_get (parsed_json , "description" )
425+ website = json_get (parsed_json , "website" )
426+ location = json_get (parsed_json , "location" )
427+ return GogsOrg (org_id = org_id , username = username , full_name = full_name ,
428+ avatar_url = avatar_url , description = description ,
429+ website = website , location = location )
430+
431+ def as_dict (self ):
432+ fields = {
433+ "id" : self ._id ,
434+ "username" : self ._username ,
435+ "full_name" : self ._full_name ,
436+ "avatar_url" : self ._avatar_url ,
437+ "description" : self ._description ,
438+ "website" : self ._website ,
439+ "location" : self ._location
440+ }
441+ return {k : v for (k , v ) in fields .items () if v is not None }
442+
443+ @property # named org_id to avoid conflict with built-in id
444+ def org_id (self ):
445+ """
446+ The organization's id
447+
448+ :rtype: int
449+ """
450+ return self ._id
451+
452+ @property
453+ def username (self ):
454+ """
455+ Organization's username
456+
457+ :rtype: str
458+ """
459+ return self ._username
460+
461+ @property
462+ def full_name (self ):
463+ """
464+ Organization's full name
465+
466+ :rtype: str
467+ """
468+ return self ._full_name
469+
470+ @property
471+ def avatar_url (self ):
472+ """
473+ Organization's avatar url
474+
475+ :rtype: str
476+ """
477+ return self ._avatar_url
478+
479+ @property
480+ def description (self ):
481+ """
482+ Organization's description
483+
484+ :rtype: str
485+ """
486+ return self ._description
487+
488+ @property
489+ def website (self ):
490+ """
491+ Organization's website address
492+
493+ :rtype: str
494+ """
495+ return self ._website
496+
497+ @property
498+ def location (self ):
499+ """
500+ Organization's location
501+
502+ :rtype: str
503+ """
504+ return self ._location
505+
506+ class Team (object ):
507+ """
508+ Team of an organization
509+ """
510+ def __init__ (self , team_id , name , description , permission ):
511+ self ._id = team_id
512+ self ._name = name
513+ self ._description = description
514+ self ._permission = permission
515+
516+ @staticmethod
517+ def from_json (parsed_json ):
518+ team_id = json_get (parsed_json , "id" )
519+ name = json_get (parsed_json , "name" )
520+ description = json_get (parsed_json , "description" )
521+ permission = json_get (parsed_json , "permission" )
522+ return GogsOrg .Team (team_id = team_id , name = name , description = description , permission = permission )
523+
524+ def as_dict (self ):
525+ fields = {
526+ "team_id" : self ._id ,
527+ "name" : self ._name ,
528+ "description" : self ._description ,
529+ "permission" : self ._permission ,
530+ }
531+ return {k : v for (k , v ) in fields .items () if v is not None }
532+
533+ @property # named team_id to avoid conflict with built-in id
534+ def team_id (self ):
535+ """
536+ Team's id
537+
538+ :rtype: int
539+ """
540+ return self ._id
541+
542+ @property
543+ def name (self ):
544+ """
545+ Team name
546+
547+ :rtype: str
548+ """
549+ return self ._name
550+
551+ @property
552+ def description (self ):
553+ """
554+ Description to the team
555+
556+ :rtype: str
557+ """
558+ return self ._description
559+
560+ @property
561+ def permission (self ):
562+ """
563+ Team permission, can be read, write or admin, default is read
564+
565+ :rtype: int
566+ """
567+ return self ._permission
568+
0 commit comments