8000 Allow adding repos to teams with specific permissions by borgstrom · Pull Request #625 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Allow adding repos to teams with specific permissions #625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 25, 2016
Merged
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
2 changes: 2 additions & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,5 @@ Contributors
- Dejan Svetec (@dsvetec)

- Billy Keyes (@bluekeyes)

- Evan Borgstrom (@borgstrom)
6 changes: 4 additions & 2 deletions github3/orgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,16 @@ def add_member(self, username):
return self._boolean(self._put(url), 204, 404)

@requires_auth
def add_repository(self, repository):
def add_repository(self, repository, permission=''):
"""Add ``repository`` to this team.

:param str repository: (required), form: 'user/repo'
:param str permission: (optional), ('pull', 'push', 'admin')
:returns: bool
"""
data = {'permission': permission}
url = self._build_url('repos', repository, base_url=self._api)
return self._boolean(self._put(url), 204, 404)
return self._boolean(self._put(url, data=dumps(data)), 204, 404)

@requires_auth
def delete(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/cassettes/Team_add_repository.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/orgs/github3py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA52SPW/CMBCG/0rlOSROIFB5adcOVRekSl2iS3CMVce2bAdEEf+9ZxJKSie6Jed77+N570iUEVITRoQM276e2wNJiNwQlq8ei7xcJqR3Cp+3IVjPsgysTIfUtDFdZpzw2VTquDW+ukOTnRXYlO+4DvdJBwlqO97V3N0nHjXHbPg4YRnb10o21X+q/ZZOi8IOArhbJOegH1H2nrvG6IAAzlT7bKT/hENp6PjVn/RsECZZ0IdJWBoM12gmYbpXKkFfGwjSRGtfYSO90cnD+0vk3IFER4escezBA1b+IBDSB08YTUhrlDJ7hDv5kxrb4Ns2dOpmscltTM+icRwC31QQcJ6C5sWMlrNitaYLVpRsvvzAwXq7+ZWzmNHVrKDrfMkoZfMi5oSDjTDenAAtv4YFMWoCqMo6iVR5NS6D85m9xp5/45fIdUsE9Fn1HgRWz+kiElYKauMgmHH1WiqFi1cjPyJcCm2bQrRMpZ3UqTC7ZxHpRhPjOSlA/MeLg63jHKPeQoNd5nRVUJzxdrrT6Rvyb5wJlAMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "132026e9262a0093e437f99db5f1e499", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"7a807b488b5268f40ea462dc5a957426\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4976", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:11E5:8BD47:53CEF47C", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Sun, 20 Jul 2014 16:00:32 GMT", "date": "Tue, 22 Jul 2014 23:32:12 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1406073636"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/orgs/github3py"}, "recorded_at": "2014-07-22T23:32:12"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/teams/189901"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA5VTyW7CMBT8lcrnLE4gUHzpuYeqF6RKvURO4gZL3uQFRBH/3kdiREBVCzf7+c1bZsYHpKhkiKD3nWLWoQTxDpHiebXCRYKcCD286fObYVZy57hWEKWd5AoAwQq4bbw3juQ5NTzrud+EJmu1zD2j0uVjPciVTDbQpr4bk0fEIR6OUMQyox332nL2SKUBNpmh1UF52DUWrOO9SpC2PVX8m/ph0QMSuodNCRr3mpn9mablc1lUi38ogGoun0KHQf6m4BqTn0dnW6b8Y9ARci/1N31/Id+ERvC2vkvIm2rX0KmidEs9tbeUDEEX3RQcs61WHggYjBXyYmT/BXaLHo4kZ4NAkGSo2l9ky7iGcANiIqKCEAno2kaN0RvtuNMqefp4hSQmKQdTj1lx7FEDAvaIgZ477xDBCfrSQujd6ftcblxBG3jbeCluFpt8j6ktWsuoZ11NwZSoxEWZ4iotl2s8J2VFZotPGCyY7ipnnuJlWuJ1sSAYk1l5yvF7M3zoqYmPxx8B305P6QMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"a7a21842a7b4f3bff9b46d086d6364aa\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4975", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:11E5:8BD98:53CEF47C", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Sat, 20 Oct 2007 11:24:19 GMT", "date": "Tue, 22 Jul 2014 23:32:13 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1406073636"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/teams/189901"}, "recorded_at": "2014-07-22T23:32:13"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Content-Length": "0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "PUT", "uri": "https://api.github.com/teams/189901/repos/github3py/urllib3"}, "response": {"body": {"string": "", "encoding": null}, "headers": {"status": "204 No Content", "x-ratelimit-remaining": "4974", "x-github-media-type": "github.v3; param=full; format=json", "x-content-type-options": "nosniff", "content-security-policy": "default-src 'none'", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "x-github-request-id": "48A0C4D3:11E5:8BDCE:53CEF47D", "strict-transport-security": "max-age=31536000; includeSubdomains", "vary": "Accept-Encoding", "server": "GitHub.com", "access-control-allow-origin": "*", "x-ratelimit-limit": "5000", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "access-control-allow-credentials": "true", "date": "Tue, 22 Jul 2014 23:32:13 GMT", "x-frame-options": "deny", "x-xss-protection": "1; mode=block", "x-ratelimit-reset": "1406073636"}, "status": {"message": "No Content", "code": 204}, "url": "https://api.github.com/teams/189901/repos/github3py/urllib3"}, "recorded_at": "2014-07-22T23:32:13"}], "recorded_with": "betamax/{version}"}
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/orgs/github3py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA52SPW/CMBCG/0rlOSROIFB5adcOVRekSl2iS3CMVce2bAdEEf+9ZxJKSie6Jed77+N570iUEVITRoQM276e2wNJiNwQlq8ei7xcJqR3Cp+3IVjPsgysTIfUtDFdZpzw2VTquDW+ukOTnRXYlO+4DvdJBwlqO97V3N0nHjXHbPg4YRnb10o21X+q/ZZOi8IOArhbJOegH1H2nrvG6IAAzlT7bKT/hENp6PjVn/RsECZZ0IdJWBoM12gmYbpXKkFfGwjSRGtfYSO90cnD+0vk3IFER4escezBA1b+IBDSB08YTUhrlDJ7hDv5kxrb4Ns2dOpmscltTM+icRwC31QQcJ6C5sWMlrNitaYLVpRsvvzAwXq7+ZWzmNHVrKDrfMkoZfMi5oSDjTDenAAtv4YFMWoCqMo6iVR5NS6D85m9xp5/45fIdUsE9Fn1HgRWz+kiElYKauMgmHH1WiqFi1cjPyJcCm2bQrRMpZ3UqTC7ZxHpRhPjOSlA/MeLg63jHKPeQoNd5nRVUJzxdrrT6Rvyb5wJlAMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "132026e9262a0093e437f99db5f1e499", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"7a807b488b5268f40ea462dc5a957426\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4976", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:11E5:8BD47:53CEF47C", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Sun, 20 Jul 2014 16:00:32 GMT", "date": "Tue, 22 Jul 2014 23:32:12 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1406073636"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/orgs/github3py"}, "recorded_at": "2014-07-22T23:32:12"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/teams/189901"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA5VTyW7CMBT8lcrnLE4gUHzpuYeqF6RKvURO4gZL3uQFRBH/3kdiREBVCzf7+c1bZsYHpKhkiKD3nWLWoQTxDpHiebXCRYKcCD286fObYVZy57hWEKWd5AoAwQq4bbw3juQ5NTzrud+EJmu1zD2j0uVjPciVTDbQpr4bk0fEIR6OUMQyox332nL2SKUBNpmh1UF52DUWrOO9SpC2PVX8m/ph0QMSuodNCRr3mpn9mablc1lUi38ogGoun0KHQf6m4BqTn0dnW6b8Y9ARci/1N31/Id+ERvC2vkvIm2rX0KmidEs9tbeUDEEX3RQcs61WHggYjBXyYmT/BXaLHo4kZ4NAkGSo2l9ky7iGcANiIqKCEAno2kaN0RvtuNMqefp4hSQmKQdTj1lx7FEDAvaIgZ477xDBCfrSQujd6ftcblxBG3jbeCluFpt8j6ktWsuoZ11NwZSoxEWZ4iotl2s8J2VFZotPGCyY7ipnnuJlWuJ1sSAYk1l5yvF7M3zoqYmPxx8B305P6QMAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"a7a21842a7b4f3bff9b46d086d6364aa\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4975", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "transfer-encoding": "chunked", "x-github-request-id": "48A0C4D3:11E5:8BD98:53CEF47C", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Sat, 20 Oct 2007 11:24:19 GMT", "date": "Tue, 22 Jul 2014 23:32:13 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1406073636"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/teams/189901"}, "recorded_at": "2014-07-22T23:32:13"}, {"request": {"body": {"string": "{\"permission\": \"\"}", "encoding": "utf-8"}, "headers": {"Content-Length": "0", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "PUT", "uri": "https://api.github.com/teams/189901/repos/github3py/urllib3"}, "response": {"body": {"string": "", "encoding": null}, "headers": {"status": "204 No Content", "x-ratelimit-remaining": "4974", "x-github-media-type": "github.v3; param=full; format=json", "x-content-type-options": "nosniff", "content-security-policy": "default-src 'none'", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "x-github-request-id": "48A0C4D3:11E5:8BDCE:53CEF47D", "strict-transport-security": "max-age=31536000; includeSubdomains", "vary": "Accept-Encoding", "server": "GitHub.com", "access-control-allow-origin": "*", "x-ratelimit-limit": "5000", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "access-control-allow-credentials": "true", "date": "Tue, 22 Jul 2014 23:32:13 GMT", "x-frame-options": "deny", "x-xss-protection": "1; mode=block", "x-ratelimit-reset": "1406073636"}, "status": {"message": "No Content", "code": 204}, "url": "https://api.github.com/teams/189901/repos/github3py/urllib3"}, "recorded_at": "2014-07-22T23:32:13"}], "recorded_with": "betamax/{version}"}
8 changes: 7 additions & 1 deletion tests/unit/test_orgs_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ def test_add_repository(self):
"""Show that one can add a repository to an organization team."""
self.instance.add_repository('name-of-repo')

self.session.put.assert_called_once_with(url_for('repos/name-of-repo'))
self.put_called_with(url_for('repos/name-of-repo'),
data={'permission': ''})

self.instance.add_repository('name-of-repo', permission='push')

self.put_called_with(url_for('repos/name-of-repo'),
data={'permission': 'push'})

def test_delete(self):
"""Show that a user can delete an organization team."""
Expand Down
0