Repository: PyGithub/PyGithub

Issue:
github.Team.Team.set_repo_permission calls a legacy API endpoint
The method [github.Team.Team.set_repo_permission](https://pygithub.readthedocs.io/en/stable/github_objects/Team.html#github.Team.Team.set_repo_permission) calls an old API-Endpoint:
https://github.com/PyGithub/PyGithub/blob/219bde53d31845ae147e14382ceeed07153dcbda/github/Team.py#L237

It calls
```python
headers, data = self._requester.requestJsonAndCheck(
   "PUT", self.url + "/repos/" + repo._identity, input=put_parameters
)
```

This endpoint is linked to [Teams: Add or update team repository (Legacy)](https://developer.github.com/v3/teams/#add-or-update-team-repository-legacy).
The new API endpoint for this is [Teams: Add or update team repository](https://developer.github.com/v3/teams/#add-or-update-team-repository): `PUT /orgs/:org/teams/:team_slug/repos/:owner/:repo`


Discussion:
Additional note:
Legacy doesn't seem to mean Deprecated. Deprecated methods seem to be marked explicitly. See https://developer.github.com/v3/teams/members/#deprecation-notice-2
Nevermind. https://developer.github.com/v3/teams/#add-or-update-team-repository-legacy has a deprecation notice. It just has a different design.
After checking the code of the current Team implementation, it seems that this is implementing the Legacy API for all endpoints: https://developer.github.com/v3/teams/

Resolving patch:
diff --git a/github/Team.py b/github/Team.py
--- a/github/Team.py
+++ b/github/Team.py
@@ -41,6 +41,8 @@
 #                                                                              #
 ################################################################################
 
+from deprecated import deprecated
+
 import github.GithubObject
 import github.NamedUser
 import github.Organization
@@ -234,6 +236,11 @@ def get_repo_permission(self, repo):
         except UnknownObjectException:
             return None
 
+    @deprecated(
+        reason="""
+        Team.set_repo_permission() is deprecated, use Team.update_team_repository() instead.
+        """
+    )
     def set_repo_permission(self, repo, permission):
         """
         :calls: `PUT /teams/:id/repos/:org/:repo <http://developer.github.com/v3/orgs/teams>`_
@@ -241,6 +248,7 @@ def set_repo_permission(self, repo, permission):
         :param permission: string
         :rtype: None
         """
+
         assert isinstance(repo, github.Repository.Repository), repo
         put_parameters = {
             "permission": permission,
@@ -249,6 +257,30 @@ def set_repo_permission(self, repo, permission):
             "PUT", self.url + "/repos/" + repo._identity, input=put_parameters
         )
 
+    def update_team_repository(self, repo, permission):
+        """
+        :calls: `PUT /orgs/:org/teams/:team_slug/repos/:owner/:repo <https://developer.github.com/v3/teams/#add-or-update-team-repository-permissions>`_
+        :param repo: string or :class:`github.Repository.Repository`
+        :param permission: string
+        :rtype: bool
+        """
+        assert isinstance(repo, github.Repository.Repository) or isinstance(
+            repo, str
+        ), repo
+        assert isinstance(permission, str), permission
+        repo_url_param = repo
+        if isinstance(repo, github.Repository.Repository):
+            repo_url_param = repo._identity
+        put_parameters = {
+            "permission": permission,
+        }
+        status, _, _ = self._requester.requestJson(
+            "PUT",
+            self.organization.url + "/teams/" + self.slug + "/repos/" + repo_url_param,
+            input=put_parameters,
+        )
+        return status == 204
+
     def delete(self):
         """
         :calls: `DELETE /teams/:id <http://developer.github.com/v3/orgs/teams>`_


Test patch:
diff --git a/tests/ReplayData/Team.setUp.txt b/tests/ReplayData/Team.setUp.txt
--- a/tests/ReplayData/Team.setUp.txt
+++ b/tests/ReplayData/Team.setUp.txt
@@ -18,5 +18,5 @@ None
 None
 200
 [('status', '200 OK'), ('x-ratelimit-remaining', '4975'), ('content-length', '145'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"03555a65309084f36bcf959063a39d35"'), ('date', 'Sat, 26 May 2012 21:09:52 GMT'), ('content-type', 'application/json; charset=utf-8')]
-{"repos_count":0,"url":"https://api.github.com/teams/189850","members_count":0,"name":"Team created by PyGithub","privacy":"closed","permission":"pull","id":189850,"organization":{"login":"BeaverSoftware","id":1424031,"url":"https://api.github.com/orgs/BeaverSoftware"}}
+{"repos_count":0,"url":"https://api.github.com/teams/189850","members_count":0,"name":"Team created by PyGithub","slug": "pygithub","privacy":"closed","permission":"pull","id":189850,"organization":{"login":"BeaverSoftware","id":1424031,"url":"https://api.github.com/orgs/BeaverSoftware"}}
 
diff --git a/tests/ReplayData/Team.testUpdateTeamRepository.txt b/tests/ReplayData/Team.testUpdateTeamRepository.txt
new file mode 100644
--- /dev/null
+++ b/tests/ReplayData/Team.testUpdateTeamRepository.txt
@@ -0,0 +1,20 @@
+https
+GET
+api.github.com
+None
+/repos/BeaverSoftware/FatherBeaver
+{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
+None
+200
+[('Date', 'Thu, 07 May 2020 12:39:27 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4971'), ('X-RateLimit-Reset', '1588858091'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding, Accept, X-Requested-With'), ('ETag', 'W/"d0c102425dbcce281d1fec14c70d888d"'), ('Last-Modified', 'Thu, 07 May 2020 12:25:17 GMT'), ('X-OAuth-Scopes', 'admin:org, repo'), ('X-Accepted-OAuth-Scopes', 'repo'), ('X-GitHub-Media-Type', 'github.v3; format=json'), ('Access-Control-Expose-Headers', 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset'), ('Access-Control-Allow-Origin', '*'), ('Strict-Transport-Security', 'max-age=31536000; includeSubdomains; preload'), ('X-Frame-Options', 'deny'), ('X-Content-Type-Options', 'nosniff'), ('X-XSS-Protection', '1; mode=block'), ('Referrer-Policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('Content-Security-Policy', "default-src 'none'"), ('Content-Encoding', 'gzip')]
+{"name":"FatherBeaver","full_name":"BeaverSoftware/FatherBeaver","private":false,"owner":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031},"html_url":"https://github.com/BeaverSoftware/FatherBeaver","description":"","fork":false,"url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","created_at":"2012-02-09T19:32:21Z","updated_at":"2012-02-16T21:51:15Z","svn_url":"https://github.com/BeaverSoftware/FatherBeaver","git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","homepage":"","size":0,"mirror_url":null,"has_downloads":true,"watchers":2,"permissions":{"pull":true,"admin":true,"push":true},"has_wiki":true,"has_issues":true,"forks":1,"open_issues":0,"language":null,"pushed_at":null,"id":3400397,"organization":{"url":"https://api.github.com/users/BeaverSoftware","avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031}}
+
+https
+PUT
+api.github.com
+None
+/orgs/BeaverSoftware/teams/pygithub/repos/BeaverSoftware/FatherBeaver
+{"Authorization": "Basic login_and_password_removed", "Content-Type": "application/json", "User-Agent": "PyGithub/Python"}
+{"permission": "admin"}
+204
+[]
diff --git a/tests/Team.py b/tests/Team.py
--- a/tests/Team.py
+++ b/tests/Team.py
@@ -110,6 +110,10 @@ def testRepoPermission(self):
         repo = self.org.get_repo("FatherBeaver")
         self.team.set_repo_permission(repo, "admin")
 
+    def testUpdateTeamRepository(self):
+        repo = self.org.get_repo("FatherBeaver")
+        self.assertTrue(self.team.update_team_repository(repo, "admin"))
+
     def testRepos(self):
         repo = self.org.get_repo("FatherBeaver")
         self.assertListKeyEqual(self.team.get_repos(), None, [])