Skip to content

Commit c3ee062

Browse files
costibleotuethantkoenig
authored andcommitted
Webhooks, Organisations Administration, Repo migrate, List user repos (#7)
* Specify organization when creating a repo. * New line at end of file * Webhook entity representation. * Create, update and delete hooks. * Added GogsHookUpdate in import * Created tests for hook creation and update * Fix for python3 in test_update_user1 and test_update_hook1 * Test hooks list and delete. * Created Organization and Team entity * Created all administration for organization * Added GogsOrg * Import GogsOrg * Added tests for Administration Organization * Added model for deployment key * Added methods for deploy keys * Added tests for deploy keys * Added migrate_repo * Fixed uid type to int in migrate_repo docs. * First drone file * added all feature branches to drone * test file for drone * testing drone * testing drone * drone - install req * drone - install test req * drone - notify via slack * List user repos * Test list user repos * Remove custom template from slack notify * Remove print statement * Added secrets in drone.yml * databus-systems drone file to gitignore * Fixed changes request
1 parent 156ddae commit c3ee062

File tree

9 files changed

+1048
-8
lines changed

9 files changed

+1048
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,5 @@ ENV/
9191
# IDE files
9292
.idea/
9393

94+
# DRONE file
95+
.drone.yml

docs/entities.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ This pages documents classes provided by ``gogs_client`` module that represent e
1717

1818
.. autoclass:: gogs_client.entities::GogsRepo.Permissions()
1919
:members:
20+
21+
.. autoclass:: gogs_client.entities::GogsRepo.Hook()
22+
:members:
23+
24+
.. autoclass:: gogs_client.entities::GogsOrg()
25+
:members:
26+
27+
.. autoclass:: gogs_client.entities::GogsOrg.Team()
28+
:members:

docs/updates.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ Updates
88

99
.. autoclass:: gogs_client.updates::GogsUserUpdate.Builder()
1010
:members:
11+
12+
.. autoclass:: GogsHookUpdate()
13+
:members:
14+
15+
.. autoclass:: gogs_client.updates::GogsHookUpdate.Builder()
16+
:members:

gogs_client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from gogs_client.auth import Authentication, Token, UsernamePassword
2-
from gogs_client.entities import GogsUser, GogsRepo
2+
from gogs_client.entities import GogsUser, GogsRepo, GogsOrg
33
from gogs_client.interface import GogsApi, ApiFailure, NetworkFailure
4-
from gogs_client.updates import GogsUserUpdate
4+
from gogs_client.updates import GogsUserUpdate, GogsHookUpdate

gogs_client/_implementation/http_utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ def options(self, relative_path, params=None, **kwargs):
3636
return self.session.options(self.absolute_url(relative_path), params=params, **kwargs)
3737

3838
def patch(self, relative_path, data=None, **kwargs):
39-
return self.session.patch(self.absolute_url(relative_path), data=data, **kwargs)
39+
return self.session.patch(self.absolute_url(relative_path), json=data, **kwargs)
4040

4141
def post(self, relative_path, data=None, **kwargs):
42-
return self.session.post(self.absolute_url(relative_path), data=data, **kwargs)
42+
return self.session.post(self.absolute_url(relative_path), json=data, **kwargs)
4343

4444
def put(self, relative_path, params=None, data=None, **kwargs):
45-
return self.session.put(self.absolute_url(relative_path), params=params, data=data, **kwargs)
45+
return self.session.put(self.absolute_url(relative_path), params=params, json=data, **kwargs)
4646

4747

4848
def append_url(base_url, path):

gogs_client/entities.py

Lines changed: 326 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)