diff --git a/github2/organizations.py b/github2/organizations.py index 25df990..eb2f50a 100644 --- a/github2/organizations.py +++ b/github2/organizations.py @@ -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 @@ -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') + + diff --git a/github2/request.py b/github2/request.py index d350d55..cc61378 100644 --- a/github2/request.py +++ b/github2/request.py @@ -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() diff --git a/github2/teams.py b/github2/teams.py index 859a40e..97c9033 100644 --- a/github2/teams.py +++ b/github2/teams.py @@ -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 @@ -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