Repository: PyGithub/PyGithub

Issue:
Support for "Review a user's permission level"
Support endpoint:
https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level

I'm not exactly sure what should the accessors:
```python
repo.get_collaborator_permissions("userlogin")
```

Note that it's not the same as listing collaborators and check "permission" node, the string content is not the same.

Thought? (at least on the expected Python syntax)


Discussion:
@lmazuel Indeed, this is missing. Do you want to submit a PR so we can review together? Maybe call it like `review_collaborator_permission`.
Sure, I patched my own version so I should definitely be able to do a PR. I do that asap.
@lmazuel Any chance to work on the PR?

Resolving patch:
diff --git a/github/Repository.py b/github/Repository.py
--- a/github/Repository.py
+++ b/github/Repository.py
@@ -788,6 +788,21 @@ def add_to_collaborators(self, collaborator, permission=github.GithubObject.NotS
         return github.Invitation.Invitation(self._requester, headers, data, completed=True) if \
             data is not None else None
 
+    def get_collaborator_permission(self, collaborator):
+        """
+        :calls: `GET /repos/:owner/:repo/collaborators/:username/permission <http://developer.github.com/v3/repos/collaborators>`_
+        :param collaborator: string or :class:`github.NamedUser.NamedUser`
+        :rtype: string
+        """
+        assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, unicode)), collaborator
+        if isinstance(collaborator, github.NamedUser.NamedUser):
+            collaborator = collaborator._identity
+        headers, data = self._requester.requestJsonAndCheck(
+            "GET",
+            self.url + "/collaborators/" + collaborator + "/permission",
+        )
+        return data["permission"]
+
     def compare(self, base, head):
         """
         :calls: `GET /repos/:owner/:repo/compare/:base...:head <http://developer.github.com/v3/repos/commits>`_


Test patch:
diff --git a/github/tests/ReplayData/Repository.testCollaboratorPermission.txt b/github/tests/ReplayData/Repository.testCollaboratorPermission.txt
new file mode 100644
--- /dev/null
+++ b/github/tests/ReplayData/Repository.testCollaboratorPermission.txt
@@ -0,0 +1,10 @@
+https
+GET
+api.github.com
+None
+/repos/jacquev6/PyGithub/collaborators/jacquev6/permission
+{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
+None
+200
+[('x-runtime-rack', '0.032572'), ('vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding'), ('x-oauth-scopes', 'public_repo, repo:status'), ('x-xss-protection', '1; mode=block'), ('x-content-type-options', 'nosniff'), ('x-accepted-oauth-scopes', ''), ('etag', 'W/"69918ef0498799a123b1fac181217047"'), ('cache-control', 'private, max-age=60, s-maxage=60'), ('referrer-policy', 'origin-when-cross-origin, strict-origin-when-cross-origin'), ('status', '200 OK'), ('x-ratelimit-remaining', '4997'), ('x-github-media-type', 'github.v3; format=json'), ('access-control-expose-headers', 'ETag, Link, Retry-After, 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', '83E0:5916:5CBB8E:776CEA:5B834CE0'), ('date', 'Mon, 27 Aug 2018 00:59:13 GMT'), ('access-control-allow-origin', '*'), ('content-security-policy', "default-src 'none'"), ('content-encoding', 'gzip'), ('strict-transport-security', 'max-age=31536000; includeSubdomains; preload'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('x-frame-options', 'deny'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1535333556')]
+{"user":{"following_url":"https://api.github.com/users/jacquev6/following{/other_user}","events_url":"https://api.github.com/users/jacquev6/events{/privacy}","avatar_url":"https://avatars0.githubusercontent.com/u/327146?v=4","url":"https://api.github.com/users/jacquev6","gists_url":"https://api.github.com/users/jacquev6/gists{/gist_id}","html_url":"https://github.com/jacquev6","subscriptions_url":"https://api.github.com/users/jacquev6/subscriptions","node_id":"MDQ6VXNlcjE1MjI1MDU5","repos_url":"https://api.github.com/users/jacquev6/repos","received_events_url":"https://api.github.com/users/jacquev6/received_events","gravatar_id":"","starred_url":"https://api.github.com/users/jacquev6/starred{/owner}{/repo}","site_admin":false,"login":"jacquev6","type":"User","id":327146,"followers_url":"https://api.github.com/users/jacquev6/followers","organizations_url":"https://api.github.com/users/jacquev6/orgs"},"permission":"admin"}
diff --git a/github/tests/ReplayData/Repository.testCollaboratorPermissionNoPushAccess.txt b/github/tests/ReplayData/Repository.testCollaboratorPermissionNoPushAccess.txt
new file mode 100644
--- /dev/null
+++ b/github/tests/ReplayData/Repository.testCollaboratorPermissionNoPushAccess.txt
@@ -0,0 +1,10 @@
+https
+GET
+api.github.com
+None
+/repos/jacquev6/PyGithub/collaborators/lyloa/permission
+{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
+None
+403
+[('status', '403 Forbidden'), ('x-ratelimit-remaining', '4980'), ('content-length', '37'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"2743ecba84275ee9f0aa8e9edc5ed691"'), ('date', 'Mon, 27 Aug 2018 01:10:27 GMT'), ('content-type', 'application/json; charset=utf-8')]
+{"documentation_url": "https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level", "message": "Must have push access to view collaborator permission."}
diff --git a/github/tests/Repository.py b/github/tests/Repository.py
--- a/github/tests/Repository.py
+++ b/github/tests/Repository.py
@@ -296,6 +296,19 @@ def testCollaborators(self):
         self.repo.remove_from_collaborators(lyloa)
         self.assertFalse(self.repo.has_in_collaborators(lyloa))
 
+    def testCollaboratorPermission(self):
+        self.assertEqual(self.repo.get_collaborator_permission('jacquev6'), 'admin')
+
+    def testCollaboratorPermissionNoPushAccess(self):
+        with self.assertRaises(github.GithubException) as raisedexp:
+            self.repo.get_collaborator_permission('lyloa')
+        self.assertEqual(raisedexp.exception.status, 403)
+        self.assertEqual(raisedexp.exception.data, {
+            u'documentation_url': u'https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level',
+            u'message': u'Must have push access to view collaborator permission.'
+            }
+        )
+
     def testCompare(self):
         comparison = self.repo.compare("v0.6", "v0.7")
         self.assertEqual(comparison.status, "ahead")