Skip to content

Webhooks, Organisations Administration, Repo migrate, List user repos #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f2808cc
Specify organization when creating a repo.
Mar 30, 2017
5787c9a
New line at end of file
Mar 30, 2017
bd7ac3a
Webhook entity representation.
Mar 30, 2017
f1bdd3a
Create, update and delete hooks.
Mar 31, 2017
4c2c477
Added GogsHookUpdate in import
Apr 3, 2017
abd3c01
Created tests for hook creation and update
Apr 3, 2017
95e368d
Fix for python3 in test_update_user1 and test_update_hook1
Apr 3, 2017
403d252
Test hooks list and delete.
Apr 3, 2017
428cd56
Created Organization and Team entity
Apr 3, 2017
89c154c
Created all administration for organization
Apr 3, 2017
6a9e527
Added GogsOrg
Apr 4, 2017
b66c5b8
Import GogsOrg
Apr 4, 2017
aa93e86
Added tests for Administration Organization
Apr 4, 2017
557b267
Added model for deployment key
Apr 4, 2017
42881da
Added methods for deploy keys
Apr 4, 2017
2dd75ee
Added tests for deploy keys
Apr 4, 2017
f822715
Added migrate_repo
Apr 5, 2017
f899c40
Fixed uid type to int in migrate_repo docs.
Apr 10, 2017
0b8fd17
First drone file
Apr 10, 2017
c101f86
added all feature branches to drone
Apr 10, 2017
5216f44
test file for drone
Apr 10, 2017
3f8c205
testing drone
Apr 10, 2017
f942de3
testing drone
Apr 10, 2017
042c6f7
drone - install req
Apr 10, 2017
9388996
drone - install test req
Apr 10, 2017
4efbf3f
drone - notify via slack
Apr 10, 2017
dbce610
List user repos
Apr 11, 2017
748bc7c
Test list user repos
Apr 11, 2017
5d74675
Remove custom template from slack notify
Apr 11, 2017
a31513a
Remove print statement
Apr 11, 2017
745a009
Added secrets in drone.yml
Apr 11, 2017
12db57a
databus-systems drone file to gitignore
Apr 11, 2017
05b4291
Fixed changes request
Apr 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,5 @@ ENV/
# IDE files
.idea/

# DRONE file
.drone.yml
9 changes: 9 additions & 0 deletions docs/entities.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ This pages documents classes provided by ``gogs_client`` module that represent e

.. autoclass:: gogs_client.entities::GogsRepo.Permissions()
:members:

.. autoclass:: gogs_client.entities::GogsRepo.Hook()
:members:

.. autoclass:: gogs_client.entities::GogsOrg()
:members:

.. autoclass:: gogs_client.entities::GogsOrg.Team()
:members:
6 changes: 6 additions & 0 deletions docs/updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ Updates

.. autoclass:: gogs_client.updates::GogsUserUpdate.Builder()
:members:

.. autoclass:: GogsHookUpdate()
:members:

.. autoclass:: gogs_client.updates::GogsHookUpdate.Builder()
:members:
4 changes: 2 additions & 2 deletions gogs_client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gogs_client.auth import Authentication, Token, UsernamePassword
from gogs_client.entities import GogsUser, GogsRepo
from gogs_client.entities import GogsUser, GogsRepo, GogsOrg
from gogs_client.interface import GogsApi, ApiFailure, NetworkFailure
from gogs_client.updates import GogsUserUpdate
from gogs_client.updates import GogsUserUpdate, GogsHookUpdate
6 changes: 3 additions & 3 deletions gogs_client/_implementation/http_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ def options(self, relative_path, params=None, **kwargs):
return self.session.options(self.absolute_url(relative_path), params=params, **kwargs)

def patch(self, relative_path, data=None, **kwargs):
return self.session.patch(self.absolute_url(relative_path), data=data, **kwargs)
return self.session.patch(self.absolute_url(relative_path), json=data, **kwargs)

def post(self, relative_path, data=None, **kwargs):
return self.session.post(self.absolute_url(relative_path), data=data, **kwargs)
return self.session.post(self.absolute_url(relative_path), json=data, **kwargs)

def put(self, relative_path, params=None, data=None, **kwargs):
return self.session.put(self.absolute_url(relative_path), params=params, data=data, **kwargs)
return self.session.put(self.absolute_url(relative_path), params=params, json=data, **kwargs)


def append_url(base_url, path):
Expand Down
326 changes: 326 additions & 0 deletions gogs_client/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,329 @@ def pull(self):
:rtype: bool
"""
return self._pull

class Hook(object):
def __init__(self, hook_id, hook_type, events, active, config):
self._id = hook_id
self._type = hook_type
self._events = events
self._active = active
self._config = config

@staticmethod
def from_json(parsed_json):
hook_id = json_get(parsed_json, "id")
hook_type = json_get(parsed_json, "type")
events = json_get(parsed_json, "events")
active = json_get(parsed_json, "active")
config = json_get(parsed_json, "config")

return GogsRepo.Hook(hook_id=hook_id, hook_type=hook_type, events=events, active=active,
config=config)

def as_dict(self):
fields = {
"id": self._id,
"type": self._type,
"events": self._events,
"config": self._config,
"active": self._active,
}
return {k: v for (k, v) in fields.items() if v is not None}

@property # named hook_id to avoid conflict with built-in id
def hook_id(self):
"""
The hook's id number

:rtype: int
"""
return self._id

@property # named hook_type to avoid conflict with built-in type
def hook_type(self):
"""
The hook's type (gogs, slack, etc.)

:rtype: str
"""
return self._type

@property
def events(self):
"""
The events that fire the hook

:rtype: List[str]
"""
return self._events

@property
def active(self):
"""
Whether the hook is active

:rtype: bool
"""
return self._active

@property
def config(self):
"""
Config of the hook. Contains max. 3 keys:
- content_type
- url
- secret

:rtype: dict
"""
return self._config

class DeployKey(object):
def __init__(self, key_id, key, url, title, created_at, read_only):
self._id = key_id
self._key = key
self._url = url
self._title = title
self._created_at = created_at
self._read_only = read_only

@staticmethod
def from_json(parsed_json):
key_id = json_get(parsed_json, "id")
key = json_get(parsed_json, "key")
url = json_get(parsed_json, "url")
title = json_get(parsed_json, "title")
created_at = json_get(parsed_json, "created_at")
read_only = json_get(parsed_json, "read_only")

return GogsRepo.DeployKey(key_id=key_id, key=key, url=url,
title=title, created_at=created_at, read_only=read_only)

def as_dict(self):
fields = {
"id": self._id,
"key": self._key,
"url": self._url,
"title": self._title,
"created_at": self._created_at,
"read_only": self._read_only,
}
return {k: v for (k, v) in fields.items() if v is not None}

@property # named key_id to avoid conflict with built-in id
def key_id(self):
"""
The key's id number

:rtype: int
"""
return self._id

@property
def key(self):
"""
The content of the key

:rtype: str
"""
return self._key

@property
def url(self):
"""
Url where the key can be found

:rtype: str
"""
return self._url

@property
def title(self):
"""
The name of the key

:rtype: str
"""
return self._title

@property
def created_at(self):
"""
Creation date of the key.
:rtype: str
"""
return self._created_at

@property
def read_only(self):
"""
Whether key is read-only.
:rtype: bool
"""
return self._read_only

class GogsOrg(object):
"""
An immutable representation of a Gogs Organization.
"""
def __init__(self, org_id, username, full_name, avatar_url, description, website, location):
self._id = org_id
self._username = username
self._full_name = full_name
self._avatar_url = avatar_url
self._description = description
self._website = website
self._location = location

@staticmethod
def from_json(parsed_json):
org_id = json_get(parsed_json, "id")
username = json_get(parsed_json, "username")
full_name = json_get(parsed_json, "full_name")
avatar_url = json_get(parsed_json, "avatar_url")
description = json_get(parsed_json, "description")
website = json_get(parsed_json, "website")
location = json_get(parsed_json, "location")
return GogsOrg(org_id=org_id, username=username, full_name=full_name,
avatar_url=avatar_url, description=description,
website=website, location=location)

def as_dict(self):
fields = {
"id": self._id,
"username": self._username,
"full_name": self._full_name,
"avatar_url": self._avatar_url,
"description": self._description,
"website": self._website,
"location": self._location
}
return {k: v for (k, v) in fields.items() if v is not None}

@property # named org_id to avoid conflict with built-in id
def org_id(self):
"""
The organization's id

:rtype: int
"""
return self._id

@property
def username(self):
"""
Organization's username

:rtype: str
"""
return self._username

@property
def full_name(self):
"""
Organization's full name

:rtype: str
"""
return self._full_name

@property
def avatar_url(self):
"""
Organization's avatar url

:rtype: str
"""
return self._avatar_url

@property
def description(self):
"""
Organization's description

:rtype: str
"""
return self._description

@property
def website(self):
"""
Organization's website address

:rtype: str
"""
return self._website

@property
def location(self):
"""
Organization's location

:rtype: str
"""
return self._location

class Team(object):
"""
Team of an organization
"""
def __init__(self, team_id, name, description, permission):
self._id = team_id
self._name = name
self._description = description
self._permission = permission

@staticmethod
def from_json(parsed_json):
team_id = json_get(parsed_json, "id")
name = json_get(parsed_json, "name")
description = json_get(parsed_json, "description")
permission = json_get(parsed_json, "permission")
return GogsOrg.Team(team_id=team_id, name=name, description=description, permission=permission)

def as_dict(self):
fields = {
"team_id": self._id,
"name": self._name,
"description": self._description,
"permission": self._permission,
}
return {k: v for (k, v) in fields.items() if v is not None}

@property # named team_id to avoid conflict with built-in id
def team_id(self):
"""
Team's id

:rtype: int
"""
return self._id

@property
def name(self):
"""
Team name

:rtype: str
"""
return self._name

@property
def description(self):
"""
Description to the team

:rtype: str
"""
return self._description

@property
def permission(self):
"""
Team permission, can be read, write or admin, default is read

:rtype: int
"""
return self._permission

Loading