Skip to content
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

Revert having allowed values for add_to_collaborators #2905

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions github/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,11 @@ def add_to_collaborators(self, collaborator: str | NamedUser, permission: Opt[st
"""
:calls: `PUT /repos/{owner}/{repo}/collaborators/{user} <https://docs.github.com/en/rest/collaborators/collaborators#add-a-repository-collaborator>`_
:param collaborator: string or :class:`github.NamedUser.NamedUser`
:param permission: string 'pull', 'push', 'admin', 'maintain', or 'triage'
:param permission: string 'pull', 'push', 'admin', 'maintain', 'triage', or a custom repository role name, if the owning organization has defined any
:rtype: None
"""
assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, str), collaborator
assert permission in ["pull", "push", "admin", "maintain", "triage", NotSet], permission
assert is_optional(permission, str), permission

if isinstance(collaborator, github.NamedUser.NamedUser):
collaborator = collaborator._identity
Expand Down
20 changes: 20 additions & 0 deletions tests/ReplayData/Repository.testAddToCollaboratorsCustomRole.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
https
GET
api.github.com
None
/users/Lyloa
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('content-length', '554'), ('x-ratelimit-limit', '5000'), ('x-ratelimit-remaining', '4955'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('etag', '"4e931612aa9051643f0a428d2ae60b2e"'), ('date', 'Sun, 27 May 2012 05:34:26 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"type":"User","url":"https://api.github.com/users/Lyloa","html_url":"https://github.com/Lyloa","company":null,"gravatar_id":"1517ed584458ccf83e03f5d77d9699d7","avatar_url":"https://secure.gravatar.com/avatar/1517ed584458ccf83e03f5d77d9699d7?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","followers":1,"following":0,"created_at":"2011-10-16T14:36:46Z","blog":null,"login":"Lyloa","public_gists":0,"hireable":false,"name":"Lyloa","bio":null,"id":1131432,"public_repos":0,"location":"Paris","email":"nyu@lyloa.net"}

https
PUT
api.github.com
None
/repos/jacquev6/PyGithub/collaborators/Lyloa
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python', 'Content-Type': 'application/json'}
{"permission": "custom_role"}
204
[('status', '204 No Content'), ('x-ratelimit-remaining', '4953'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"d41d8cd98f00b204e9800998ecf8427e"'), ('date', 'Sun, 27 May 2012 05:34:27 GMT')]
4 changes: 4 additions & 0 deletions tests/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,10 @@ def testCollaborators(self):
def testCollaboratorPermission(self):
self.assertEqual(self.repo.get_collaborator_permission("jacquev6"), "admin")

def testAddToCollaboratorsCustomRole(self):
lyloa = self.g.get_user("Lyloa")
self.repo.add_to_collaborators(lyloa, "custom_role")

def testGetPendingInvitations(self):
lyloa = self.g.get_user("Lyloa")
self.repo.add_to_collaborators(lyloa)
Expand Down