Skip to content

Commit 05f4e79

Browse files
committed
Added method to add a new team.
Thanks to Clint Savage, refs ask#69.
1 parent b0c12a7 commit 05f4e79

4 files changed

+62
-1
lines changed

github2/organizations.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
1+
from github2.core import (BaseData, GithubCommand, Attribute, DateAttribute,
2+
requires_auth)
23
from github2.repositories import Repository
34
from github2.teams import Team
45
from github2.users import User
@@ -81,3 +82,18 @@ def teams(self, organization):
8182
"""
8283
return self.get_values(organization, 'teams', filter="teams",
8384
datatype=Team)
85+
86+
@requires_auth
87+
def add_team(self, organization, name, permission='pull', projects=None):
88+
"""Add a team to an organization
89+
90+
:param str organization: organization to add team to
91+
:param str team: name of team to add
92+
:param str permission: permissions for team(push, pull or admin)
93+
:param list projects: optional GitHub projects for this team
94+
"""
95+
team_data = {'team[name]': name, 'team[permission]': permission}
96+
if projects:
97+
team_data['team[repo_names][]'] = projects
98+
return self.get_value(organization, 'teams', post_data=team_data,
99+
method='POST', filter='team', datatype=Team)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
status: 200
2+
x-ratelimit-remaining: 60
3+
content-location: https://github.com/api/v2/json/organizations/JNRowe-test-org/teams
4+
x-runtime: 20ms
5+
content-length: 61
6+
server: nginx/1.0.4
7+
connection: keep-alive
8+
x-ratelimit-limit: 58
9+
etag: "0ea8a446a00b4d7894676a34bd8d501f"
10+
cache-control: private, max-age=0, must-revalidate
11+
date: Mon, 19 Dec 2011 20:50:41 GMT
12+
content-type: application/json; charset=utf-8
13+
14+
{"team":{"name":"team_pull","id":121678,"permission":"pull"}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
status: 200
2+
x-ratelimit-remaining: 60
3+
content-location: https://github.com/api/v2/json/organizations/JNRowe-test-org/teams
4+
x-runtime: 20ms
5+
content-length: 676
6+
server: nginx/1.0.4
7+
connection: keep-alive
8+
x-ratelimit-limit: 58
9+
etag: "397a2fcea970a6391b74eabcb62ed265"
10+
cache-control: private, max-age=0, must-revalidate
11+
date: Thu, 19 Dec 2011 20:50:41 GMT
12+
content-type: application/json; charset=utf-8
13+
14+
{"repositories":[{"open_issues":0,"description":"","watchers":1,"forks":1,"has_issues":true,"has_downloads":true,"fork":false,"created_at":"2011/12/18 17:36:08 -0800","homepage":"","size":0,"private":false,"name":"test1","owner":"JNRowe-test-org","has_wiki":true,"url":"https://github.com/JNRowe-test-org/test1","organization":"JNRowe-test-org"},{"open_issues":0,"description":"","watchers":1,"forks":1,"has_issues":true,"has_downloads":true,"fork":false,"created_at":"2011/12/18 17:36:24 -0800","homepage":"","size":0,"private":false,"name":"test2","owner":"JNRowe-test-org","has_wiki":true,"url":"https://github.com/JNRowe-test-org/test2","organization":"JNRowe-test-org"}]}

tests/test_organizations.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,20 @@ def test_public_members(self):
2929
members = self.client.organizations.public_members('github')
3030
assert_equals(len(members), 35)
3131
assert_equals(members[2].name, 'Ben Burkert')
32+
33+
34+
class OrganizationsEdits(utils.HttpMockAuthenticatedTestCase):
35+
def test_add_team(self):
36+
team = self.client.organizations.add_team('JNRowe-test-org',
37+
'test_pull', 'pull')
38+
assert_equals(team.name, 'team_pull')
39+
assert_equals(team.permission, 'pull')
40+
41+
def test_add_team_with_repos(self):
42+
projects = ['JNRowe-test-org/test1', 'JNRowe-test-org/test2']
43+
team = self.client.organizations.add_team('JNRowe-test-org',
44+
'test_push', 'push', projects)
45+
46+
team_repos = self.client.teams.repositories(team.id)
47+
assert_equals(['/'.join([x.organization, x.name]) for x in team_repos],
48+
projects)

0 commit comments

Comments
 (0)