Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion github2/organizations.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute, requires_auth
from github2.repositories import Repository
from github2.teams import Team
from github2.users import User
Expand Down Expand Up @@ -81,3 +81,22 @@ def teams(self, organization):
"""
return self.get_values(organization, 'teams', filter="teams",
datatype=Team)

@requires_auth
def add_team(self, organization, name, permission, repos=[]):
"""Add a team to an organization

:param str organization: org to which team will belong
:param str team: team name to add
:param str permission: choose from push, pull, or admin
:param str repos (optional): GitHub projects for this team
"""
# team_data={"teams":{"name": team, "permission": permission}}
team_data={"team[name]": name, "team[permission]": permission}

for repo in repos:
team_data["team[repo_names][]"] = "%s/%s" % (organization, repo)

return self.get_values(organization, 'teams', post_data=team_data, method='POST')


2 changes: 2 additions & 0 deletions github2/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ def make_request(self, path, extra_post_data=None, method="GET"):

extra_post_data = extra_post_data or {}
url = "/".join([self.url_prefix, quote(path)])
# print "url: %s" % url
result = self.raw_request(url, extra_post_data, method=method)
# print "result: %s" % result

if self.delay:
self.last_request = datetime.datetime.now()
Expand Down
13 changes: 12 additions & 1 deletion github2/teams.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from github2.core import BaseData, GithubCommand, Attribute
from github2.core import BaseData, GithubCommand, Attribute, requires_auth
from github2.repositories import Repository
from github2.users import User

Expand Down Expand Up @@ -32,6 +32,17 @@ def members(self, team_id):
return self.get_values(str(team_id), "members", filter="users",
datatype=User)

@requires_auth
def add_member(self, team_id, username):
"""Add a member to a team

:param int team_id: team to add new member
:param str username: username to add
"""
member_data={"name": username}

return self.get_values(str(team_id), 'members', post_data=member_data, method='POST')

def repositories(self, team_id):
"""Get list of all team members

Expand Down