Source code for github2.teams
# Copyright (C) 2011-2012 James Rowe <jnrowe@gmail.com>
# Patryk Zawadzki <patrys@pld-linux.org>
#
# This file is part of python-github2, and is made available under the 3-clause
# BSD license. See LICENSE for the full details.
from github2.core import BaseData, GithubCommand, Attribute, requires_auth
from github2.repositories import Repository
from github2.users import User
[docs]class Team(BaseData):
"""Team container.
.. versionadded:: 0.4.0
"""
id = Attribute("The team id")
name = Attribute("Name of the team")
permission = Attribute("Permissions of the team")
def __repr__(self):
return "<Team: %s>" % self.name
[docs]class Teams(GithubCommand):
"""GitHub API teams functionality.
.. versionadded:: 0.4.0
"""
domain = "teams"
[docs] def show(self, team_id):
"""Get information on team_id.
:param int team_id: team to get information for
"""
return self.get_value(str(team_id), filter="team", datatype=Team)
[docs] def members(self, team_id):
"""Get list of all team members.
:param int team_id: team to get information for
"""
return self.get_values(str(team_id), "members", filter="users",
datatype=User)
@requires_auth
[docs] def add_member(self, team_id, username):
"""Add a new member to a team.
:param int team_id: team to add new member to
:param str username: GitHub username to add to team
"""
return self.get_values(str(team_id), 'members', method='POST',
post_data={'name': username}, filter='users',
datatype=User)
[docs] def repositories(self, team_id):
"""Get list of all team repositories.
:param int team_id: team to get information for
"""
return self.get_values(str(team_id), "repositories",
filter="repositories", datatype=Repository)
@requires_auth
[docs] def add_project(self, team_id, project):
"""Add a project to a team.
:param int team_id: team to add repository to
:param str project: GitHub project
"""
if isinstance(project, Repository):
project = project.project
return self.get_values(str(team_id), "repositories", method="POST",
post_data={'name': project},
filter="repositories", datatype=Repository)
@requires_auth
[docs] def remove_project(self, team_id, project):
"""Remove a project to a team.
:param int team_id: team to remove project from
:param str project: GitHub project
"""
if isinstance(project, Repository):
project = project.project
return self.get_values(str(team_id), "repositories", method="DELETE",
post_data={'name': project},
filter="repositories", datatype=Repository)