aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/services
diff options
context:
space:
mode:
authorStefano Rivera <stefano@rivera.za.net>2012-04-24 10:42:25 +0200
committerStefano Rivera <stefano@rivera.za.net>2012-04-24 10:42:25 +0200
commit52b4a5db0be700fe6b48bfe1e0bda2bd86294db7 (patch)
tree2f914320c4f3813ec8a0058abb189fae822bb4ed /pygithub3/services
parentAn empty string doesn't work around the 411 issue on PUTs. Use 'PLACEHOLDER' (diff)
downloadpython-github3-52b4a5db0be700fe6b48bfe1e0bda2bd86294db7.tar.xz
python-github3-52b4a5db0be700fe6b48bfe1e0bda2bd86294db7.zip
Add Teams Service
Diffstat (limited to 'pygithub3/services')
-rw-r--r--pygithub3/services/orgs/__init__.py2
-rw-r--r--pygithub3/services/orgs/teams.py147
2 files changed, 149 insertions, 0 deletions
diff --git a/pygithub3/services/orgs/__init__.py b/pygithub3/services/orgs/__init__.py
index 6a75081..8499719 100644
--- a/pygithub3/services/orgs/__init__.py
+++ b/pygithub3/services/orgs/__init__.py
@@ -2,6 +2,7 @@
from pygithub3.services.base import Service
from .members import Members
+from .teams import Teams
class Org(Service):
@@ -9,6 +10,7 @@ class Org(Service):
def __init__(self, **config):
self.members = Members(**config)
+ self.teams = Teams(**config)
super(Org, self).__init__(**config)
def list(self, user=None):
diff --git a/pygithub3/services/orgs/teams.py b/pygithub3/services/orgs/teams.py
new file mode 100644
index 0000000..2e47803
--- /dev/null
+++ b/pygithub3/services/orgs/teams.py
@@ -0,0 +1,147 @@
+# -*- encoding: utf-8 -*-
+
+from . import Service
+
+
+class Teams(Service):
+ """ Consume `Teams API <http://developer.github.com/v3/orgs/teams/>`_
+
+ .. warning ::
+ You must be authenticated as an owner of the org
+ """
+
+ def list(self, org):
+ """ Get org's teams
+
+ :param str org: Organisation name
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('orgs.teams.list', org=org)
+ return self._get_result(request)
+
+ def get(self, id):
+ """ Get a team
+
+ :param int id: The team id
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('orgs.teams.get', id=id)
+ return self._get(request)
+
+ def create(self, org, name, repo_names=None, permission=None):
+ """ Create a new team
+
+ :param str org: Organisation name
+ :param str name: Team name
+ :param list repo_names: List of repo names to belong to the team
+ :param str permission: Permissions to be granted to members
+ """
+ data = {'name': name}
+ if repo_names:
+ data['repo_names'] = repo_names
+ if permission:
+ data['permission'] = permission
+ request = self.request_builder('orgs.teams.create', org=org, body=data)
+ return self._post(request)
+
+ def update(self, id, name, permission=None):
+ """ Update a team
+
+ :param int id: The team id
+ :param str name: Team name
+ :param str permission: Permissions to be granted to members
+ """
+ data = {'name': name}
+ if permission:
+ data['permission'] = permission
+ request = self.request_builder('orgs.teams.update', id=id, body=data)
+ return self._patch(request)
+
+ def delete(self, id):
+ """ Delete a team
+
+ :param int id: The team id
+ """
+ request = self.request_builder('orgs.teams.delete', id=id)
+ return self._delete(request)
+
+ def list_members(self, id):
+ """ List the members of a team
+
+ :param int id: The team id
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('orgs.teams.list_members', id=id)
+ return self._get_result(request)
+
+ def is_member(self, id, user):
+ """ Determine if user is a member of a team
+
+ :param int id: The team id
+ :param str user: User name
+ """
+ request = self.request_builder('orgs.teams.is_member',
+ id=id, user=user)
+ return self._bool(request)
+
+ def add_member(self, id, user):
+ """ Add a user to a team
+
+ :param int id: The team id
+ :param str user: User name
+ """
+ request = self.request_builder('orgs.teams.add_member',
+ id=id, user=user)
+ return self._put(request)
+
+ def remove_member(self, id, user):
+ """ Remove a member from a team
+
+ :param int id: The team id
+ :param str user: User name
+ """
+ request = self.request_builder('orgs.teams.remove_member',
+ id=id, user=user)
+ return self._delete(request)
+
+ def list_repos(self, id):
+ """ List the repos that a team's members get access to
+
+ :param int id: The team id
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('orgs.teams.list_repos', id=id)
+ return self._get_result(request)
+
+ def contains_repo(self, id, user, repo):
+ """ Determine if user is a member of a team
+
+ :param int id: The team id
+ :param str user: User name
+ :param str repo: Repo name
+ """
+ request = self.request_builder('orgs.teams.contains_repo',
+ id=id, user=user, repo=repo)
+ return self._bool(request)
+
+ def add_repo(self, id, user, repo):
+ """ Give team members access to a repo
+
+ :param int id: The team id
+ :param str user: User name
+ :param str repo: Repo name
+ """
+ request = self.request_builder('orgs.teams.add_repo',
+ id=id, user=user, repo=repo)
+ return self._put(request)
+
+ def remove_repo(self, id, user, repo):
+ """ Remove a repo from the a team
+
+ :param int id: The team id
+ :param str user: User name
+ :param str repo: Repo name
+ """
+ request = self.request_builder('orgs.teams.remove_repo',
+ id=id, user=user, repo=repo)
+ return self._delete(request)