mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 11:51:10 +00:00
Ability to filter repository collaborators (#938)
## Changes - Add `affiliation` parameter to `get_collaborators()` and use it to filter collaborators through the API - Resolves #937 PS: Would have loved to add a simple test for this but there seems to be a problem on my end using OAuth as I'm just not able to authenticate to the API during tests.
This commit is contained in:
+13
-2
@@ -60,6 +60,7 @@
|
||||
# Copyright 2018 per1234 <accounts@perglass.com> #
|
||||
# Copyright 2018 sechastain <sechastain@gmail.com> #
|
||||
# Copyright 2018 sfdye <tsfdye@gmail.com> #
|
||||
# Copyright 2018 Vinay Hegde <vinayhegde2010@gmail.com>
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
@@ -1340,16 +1341,26 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
None
|
||||
)
|
||||
|
||||
def get_collaborators(self):
|
||||
def get_collaborators(self, affiliation=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/collaborators <http://developer.github.com/v3/repos/collaborators>`_
|
||||
:param affiliation: string
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser`
|
||||
"""
|
||||
|
||||
url_parameters = dict()
|
||||
allowed_affiliations = ['outside', 'direct', 'all']
|
||||
if affiliation is not github.GithubObject.NotSet:
|
||||
assert isinstance(affiliation, str), affiliation
|
||||
assert affiliation in allowed_affiliations, \
|
||||
'Affiliation can be one of ' + ', '.join(allowed_affiliations)
|
||||
url_parameters['affiliation'] = affiliation
|
||||
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.NamedUser.NamedUser,
|
||||
self._requester,
|
||||
self.url + "/collaborators",
|
||||
None
|
||||
url_parameters
|
||||
)
|
||||
|
||||
def get_comment(self, id):
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
# Copyright 2018 Steve Kowalik <steven@wedontsleep.org> #
|
||||
# Copyright 2018 Wan Liuyang <tsfdye@gmail.com> #
|
||||
# Copyright 2018 sfdye <tsfdye@gmail.com> #
|
||||
# Copyright 2018 Vinay Hegde <vinayhegde2010@gmail.com>
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
@@ -120,3 +121,4 @@ from Issue216 import *
|
||||
from Issue278 import *
|
||||
from Issue494 import *
|
||||
from Issue572 import *
|
||||
from Issue937 import *
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2018 Vinay Hegde <vinayhegde2010@gmail.com> #
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
# #
|
||||
# PyGithub is free software: you can redistribute it and/or modify it under #
|
||||
# the terms of the GNU Lesser General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public License #
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
################################################################################
|
||||
import Framework
|
||||
|
||||
import github
|
||||
|
||||
class Issue937(Framework.TestCase):
|
||||
def setUp(self):
|
||||
Framework.TestCase.setUp(self)
|
||||
self.user = self.g.get_user()
|
||||
self.repo = self.user.get_repo("PyGithub")
|
||||
|
||||
def testCollaboratorsAffiliation(self):
|
||||
collaborators = self.repo.get_collaborators(affiliation='direct')
|
||||
self.assertListKeyEqual(collaborators, lambda u: u.login, ["hegde5"])
|
||||
with self.assertRaises(AssertionError):
|
||||
self.repo.get_collaborators(affiliation='invalid_option')
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
|
||||
https
|
||||
GET
|
||||
api.github.com
|
||||
None
|
||||
/repos/hegde5/PyGithub/collaborators?affiliation=direct
|
||||
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
|
||||
None
|
||||
200
|
||||
[('Server', 'GitHub.com'), ('Date', 'Sun, 21 Oct 2018 21:13:36 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1540157093'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP'), ('ETag', 'W/"db23c025efd980c5fc4249cde2e34de0"'), ('X-OAuth-Scopes', 'admin:gpg_key, admin:org, admin:org_hook, admin:public_key, admin:repo_hook, gist, notifications, repo, user, write:discussion'), ('X-Accepted-OAuth-Scopes', ''), ('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'), ('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'), ('X-GitHub-Request-Id', 'E700:4832:2D5EDDC:66CB0FA:5BCCEC00')]
|
||||
[{"login":"hegde5","id":8609211,"node_id":"MDQ6VXNlcjg2MDkyMTE=","avatar_url":"https://avatars2.githubusercontent.com/u/8609211?v=4","gravatar_id":"","url":"https://api.github.com/users/hegde5","html_url":"https://github.com/hegde5","followers_url":"https://api.github.com/users/hegde5/followers","following_url":"https://api.github.com/users/hegde5/following{/other_user}","gists_url":"https://api.github.com/users/hegde5/gists{/gist_id}","starred_url":"https://api.github.com/users/hegde5/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hegde5/subscriptions","organizations_url":"https://api.github.com/users/hegde5/orgs","repos_url":"https://api.github.com/users/hegde5/repos","events_url":"https://api.github.com/users/hegde5/events{/privacy}","received_events_url":"https://api.github.com/users/hegde5/received_events","type":"User","site_admin":false,"permissions":{"admin":true,"push":true,"pull":true}}]
|
||||
|
||||
Reference in New Issue
Block a user