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:
Vinay Hegde
2018-10-22 07:26:20 +08:00
committed by Wan Liuyang
parent 0a10d7cdf0
commit 5687226b47
6 changed files with 87 additions and 2 deletions
+13 -2
View File
@@ -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):