From 0aa0502ce9f427f1637a4cf87b7ffaf351cc4892 Mon Sep 17 00:00:00 2001 From: Clint Savage Date: Thu, 27 Oct 2011 00:48:13 -0600 Subject: [PATCH 1/4] added function add_team --- github2/organizations.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/github2/organizations.py b/github2/organizations.py index 25df990..5525b50 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,21 @@ 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') + From 7e511c6966ab033a83096167951ee5e563395b3a Mon Sep 17 00:00:00 2001 From: Clint Savage Date: Wed, 16 Nov 2011 09:01:32 -0700 Subject: [PATCH 2/4] add_member created in teams.py --- github2/request.py | 2 ++ github2/teams.py | 13 ++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) 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..a286d20 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(team_id, 'members', post_data=member_data, method='POST') + def repositories(self, team_id): """Get list of all team members From 47b02ec400254a81e19d08aba63d3750f1c70ab8 Mon Sep 17 00:00:00 2001 From: Clint Savage Date: Fri, 25 Nov 2011 22:34:55 -0700 Subject: [PATCH 3/4] fix add_team to use a string for the team_id in the post --- github2/teams.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github2/teams.py b/github2/teams.py index a286d20..97c9033 100644 --- a/github2/teams.py +++ b/github2/teams.py @@ -41,7 +41,7 @@ def add_member(self, team_id, username): """ member_data={"name": username} - return self.get_values(team_id, 'members', post_data=member_data, method='POST') + 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 From cd602dba7a7a8168920cb710b3eb35f4a1464a08 Mon Sep 17 00:00:00 2001 From: Clint Savage Date: Mon, 28 Nov 2011 00:09:18 -0700 Subject: [PATCH 4/4] minor adjustment to add_team fixing the issue of having 2 repos attached to a single team when the repos start the same way --- github2/organizations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/github2/organizations.py b/github2/organizations.py index 5525b50..eb2f50a 100644 --- a/github2/organizations.py +++ b/github2/organizations.py @@ -95,7 +95,8 @@ def add_team(self, organization, name, permission, repos=[]): team_data={"team[name]": name, "team[permission]": permission} for repo in repos: - team_data["team[repo_names]"] = "%s/%s" % (organization, repo) + team_data["team[repo_names][]"] = "%s/%s" % (organization, repo) return self.get_values(organization, 'teams', post_data=team_data, method='POST') +