From 2ab43073221bf5238c8e129b675cf9da967b38f8 Mon Sep 17 00:00:00 2001 From: jodelasur <34933233+jodelasur@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:16:24 +0800 Subject: [PATCH 1/3] Revert having allowed values for add_to_collaborators --- github/Repository.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index 4520840033..ca5afae1df 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -253,7 +253,9 @@ from github.DependabotAlert import DependabotAlert from github.Deployment import Deployment from github.Download import Download - from github.EnvironmentDeploymentBranchPolicy import EnvironmentDeploymentBranchPolicyParams + from github.EnvironmentDeploymentBranchPolicy import ( + EnvironmentDeploymentBranchPolicyParams, + ) from github.EnvironmentProtectionRuleReviewer import ReviewerParams from github.Event import Event from github.GitBlob import GitBlob @@ -1043,11 +1045,11 @@ def add_to_collaborators(self, collaborator: str | NamedUser, permission: Opt[st """ :calls: `PUT /repos/{owner}/{repo}/collaborators/{user} `_ :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 From ef6a59412caa27fc8159e695cdad427d420655ce Mon Sep 17 00:00:00 2001 From: jodelasur <34933233+jodelasur@users.noreply.github.com> Date: Fri, 23 Feb 2024 15:41:08 +0800 Subject: [PATCH 2/3] Revert auto-format --- github/Repository.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/github/Repository.py b/github/Repository.py index ca5afae1df..dbc2be7250 100644 --- a/github/Repository.py +++ b/github/Repository.py @@ -253,9 +253,7 @@ from github.DependabotAlert import DependabotAlert from github.Deployment import Deployment from github.Download import Download - from github.EnvironmentDeploymentBranchPolicy import ( - EnvironmentDeploymentBranchPolicyParams, - ) + from github.EnvironmentDeploymentBranchPolicy import EnvironmentDeploymentBranchPolicyParams from github.EnvironmentProtectionRuleReviewer import ReviewerParams from github.Event import Event from github.GitBlob import GitBlob From 7a9b1e0b809c00fbe03dbd390c4134a298ec3c41 Mon Sep 17 00:00:00 2001 From: jodelasur <34933233+jodelasur@users.noreply.github.com> Date: Fri, 23 Feb 2024 16:18:26 +0800 Subject: [PATCH 3/3] Add test --- ...itory.testAddToCollaboratorsCustomRole.txt | 20 +++++++++++++++++++ tests/Repository.py | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 tests/ReplayData/Repository.testAddToCollaboratorsCustomRole.txt diff --git a/tests/ReplayData/Repository.testAddToCollaboratorsCustomRole.txt b/tests/ReplayData/Repository.testAddToCollaboratorsCustomRole.txt new file mode 100644 index 0000000000..004b46a576 --- /dev/null +++ b/tests/ReplayData/Repository.testAddToCollaboratorsCustomRole.txt @@ -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')] diff --git a/tests/Repository.py b/tests/Repository.py index 4b4bb385ec..6454798276 100644 --- a/tests/Repository.py +++ b/tests/Repository.py @@ -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)