forked from ask/python-github2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteams.py
More file actions
102 lines (70 loc) · 2.96 KB
/
teams.py
File metadata and controls
102 lines (70 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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
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
class Teams(GithubCommand):
"""GitHub API teams functionality.
.. versionadded:: 0.4.0
"""
domain = "teams"
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)
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
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)
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
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
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)