Re-work PullRequest reviewer request (#765)

Add create_review_request() and delete_review_request() methods to
PullRequest, as well as renaming get_reviewer_requests() to
get_review_requests() and cleaning up its return value to firstly respect
teams, and secondly to cut out the middleman of PullRequestReviewerRequests,
which has been removed.

Fixes #597
This commit is contained in:
Steve Kowalik
2018-04-23 14:22:51 +08:00
committed by Wan Liuyang
parent 1f23c06a4d
commit e2e29918ea
7 changed files with 133 additions and 141 deletions
+57 -9
View File
@@ -49,7 +49,6 @@ import github.File
import github.IssueComment
import github.Commit
import github.PullRequestReview
import github.PullRequestReviewerRequest
class PullRequest(github.GithubObject.CompletableGithubObject):
@@ -438,6 +437,46 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
self._useAttributes(data)
return github.PullRequestReview.PullRequestReview(self._requester, headers, data, completed=True)
def create_review_request(self, reviewers=github.GithubObject.NotSet, team_reviewers=github.GithubObject.NotSet):
"""
:calls `POST /repos/:owner/:repo/pulls/:number/requested_reviewers <https://developer.github.com/v3/pulls/review_requests/>`_
:param reviewers: list of strings
:param team_reviewers: list of strings
:rtype: None
"""
post_parameters = dict()
if reviewers is not github.GithubObject.NotSet:
assert all(isinstance(element, (str, unicode)) for element in reviewers), reviewers
post_parameters["reviewers"] = reviewers
if team_reviewers is not github.GithubObject.NotSet:
assert all(isinstance(element, (str, unicode)) for element in team_reviewers), team_reviewers
post_parameters["team_reviewers"] = team_reviewers
headers, data = self._requester.requestJsonAndCheck(
"POST",
self.url + "/requested_reviewers",
input=post_parameters
)
def delete_review_request(self, reviewers=github.GithubObject.NotSet, team_reviewers=github.GithubObject.NotSet):
"""
:calls `DELETE /repos/:owner/:repo/pulls/:number/requested_reviewers <https://developer.github.com/v3/pulls/review_requests/>`_
:param reviewers: list of strings
:param team_reviewers: list of strings
:rtype: None
"""
post_parameters = dict()
if reviewers is not github.GithubObject.NotSet:
assert all(isinstance(element, (str, unicode)) for element in reviewers), reviewers
post_parameters["reviewers"] = reviewers
if team_reviewers is not github.GithubObject.NotSet:
assert all(isinstance(element, (str, unicode)) for element in team_reviewers), team_reviewers
post_parameters["team_reviewers"] = team_reviewers
headers, data = self._requester.requestJsonAndCheck(
"DELETE",
self.url + "/requested_reviewers",
input=post_parameters
)
def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet, state=github.GithubObject.NotSet, base=github.GithubObject.NotSet):
"""
:calls: `PATCH /repos/:owner/:repo/pulls/:number <http://developer.github.com/v3/pulls>`_
@@ -601,17 +640,26 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
None,
)
def get_reviewer_requests(self):
def get_review_requests(self):
"""
:calls: `GET /repos/:owner/:repo/pulls/:number/requested_reviewers <https://developer.github.com/v3/pulls/review_requests/>`_
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.PullRequestReviewerRequest.PullRequestReviewerRequest`
:rtype: tuple of :class:`github.PaginatedList.PaginatedList` of :class:`github.NamedUser.NamedUser` and of :class:`github.PaginatedList.PaginatedList` of :class:`github.Team.Team`
"""
return github.PaginatedList.PaginatedList(
github.PullRequestReviewerRequest.PullRequestReviewerRequest,
self._requester,
self.url + "/requested_reviewers",
None,
list_item='users'
return (
github.PaginatedList.PaginatedList(
github.NamedUser.NamedUser,
self._requester,
self.url + "/requested_reviewers",
None,
list_item='users'
),
github.PaginatedList.PaginatedList(
github.Team.Team,
self._requester,
self.url + "/requested_reviewers",
None,
list_item='teams'
)
)
def get_labels(self):
-64
View File
@@ -1,64 +0,0 @@
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2017 Aaron Levine <allevin@sandia.gov> #
# Copyright 2018 Wan Liuyang <tsfdye@gmail.com> #
# Copyright 2018 sfdye <tsfdye@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 github.GithubObject
import github.NamedUser
class PullRequestReviewerRequest(github.GithubObject.CompletableGithubObject):
"""
This class represents PullRequestReviewerRequests. The reference can be found here https://developer.github.com/v3/pulls/review_requests/
"""
def __repr__(self):
return self.get__repr__({"id": self._id.value, "login": self._login.value})
@property
def login(self):
"""
:type: string
"""
self._completeIfNotSet(self._login)
return self._login.value
@property
def id(self):
"""
:type: integer
"""
self._completeIfNotSet(self._id)
return self._id.value
def _initAttributes(self):
self._login = github.GithubObject.NotSet
self._id = github.GithubObject.NotSet
def _useAttributes(self, attributes):
if "login" in attributes: # pragma no branch
self._login = self._makeStringAttribute(attributes["login"])
if "id" in attributes: # pragma no branch
self._id = self._makeIntAttribute(attributes["id"])
-1
View File
@@ -70,7 +70,6 @@ from Organization import *
from PullRequest import *
from PullRequestComment import *
from PullRequestReview import *
from PullRequestReviewerRequests import *
from PullRequestFile import *
from RateLimiting import *
from Repository import *
+10
View File
@@ -98,6 +98,16 @@ class PullRequest(Framework.TestCase):
comment = self.pull.get_issue_comment(8387331)
self.assertEqual(comment.body, "Issue comment created by PyGithub")
def testReviewRequests(self):
self.pull.create_review_request(reviewers="sfdye", team_reviewers="pygithub-owners")
review_requests = self.pull.get_review_requests()
self.assertListKeyEqual(review_requests[0], lambda c: c.login, ["sfdye"])
self.assertListKeyEqual(review_requests[1], lambda c: c.slug, ["pygithub-owners"])
self.pull.delete_review_request(reviewers="sfdye")
review_requests = self.pull.get_review_requests()
self.assertEqual(list(review_requests[0]), [])
self.assertListKeyEqual(review_requests[1], lambda c: c.slug, ["pygithub-owners"])
def testEditWithoutArguments(self):
self.pull.edit()
@@ -1,45 +0,0 @@
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2017 Aaron Levine <allevin@sandia.gov> #
# Copyright 2017 Simon <spam@esemi.ru> #
# Copyright 2018 sfdye <tsfdye@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
class PullRequestReviewerRequests(Framework.TestCase):
def setUp(self):
Framework.TestCase.setUp(self)
self.repo = self.g.get_repo("PyGithub/PyGithub")
self.pull = self.repo.get_pull(538)
self.pullreviewerrequests = self.pull.get_reviewer_requests()
self.pullreviewerrequest = self.pullreviewerrequests[0]
def testAttributes(self):
self.assertEqual(self.pullreviewerrequest.id, 2930472)
self.assertEqual(self.pullreviewerrequest.login, "jayfk")
# test __repr__() based on this attributes
self.assertEqual(self.pullreviewerrequest.__repr__(), 'PullRequestReviewerRequest(login="jayfk", id=2930472)')
@@ -0,0 +1,66 @@
https
POST
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'Content-Type': 'application/json', 'User-Agent': 'PyGithub/Python'}
{"reviewers":"sfdye","team_reviewers":"pygithub-owners"}
201
''
https
GET
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '1153'), ('server', 'nginx'), ('last-modified', 'Sat, 03 Nov 2012 08:19:40 GMT'), ('connection', 'keep-alive'), ('etag', '"1ec7d9f2ebb27db7dc002f1382d23975"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 03 Nov 2012 08:19:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"users":[{"login":"sfdye","id":343369,"avatar_url":"https://avatars2.githubusercontent.com/u/343369?v=4","gravatar_id":"","url":"https://api.github.com/users/sfdye","html_url":"https://github.com/sfdye","followers_url":"https://api.github.com/users/sfdye/followers","following_url":"https://api.github.com/users/sfdye/following{/other_user}","gists_url":"https://api.github.com/users/sfdye/gists{/gist_id}","starred_url":"https://api.github.com/users/sfdye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfdye/subscriptions","organizations_url":"https://api.github.com/users/sfdye/orgs","repos_url":"https://api.github.com/users/sfdye/repos","events_url":"https://api.github.com/users/sfdye/events{/privacy}","received_events_url":"https://api.github.com/users/sfdye/received_events","type":"User","site_admin":false}],"teams":[{"name":"pygithub-owners","id":585225,"slug":"pygithub-owners","description":"","privacy":"closed","url":"https://api.github.com/teams/585225","members_url":"https://api.github.com/teams/585225/members{/member}","repositories_url":"https://api.github.com/teams/585225/repos","permission":"pull"}]}
https
GET
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '1153'), ('server', 'nginx'), ('last-modified', 'Sat, 03 Nov 2012 08:19:40 GMT'), ('connection', 'keep-alive'), ('etag', '"1ec7d9f2ebb27db7dc002f1382d23975"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 03 Nov 2012 08:19:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"users":[{"login":"sfdye","id":343369,"avatar_url":"https://avatars2.githubusercontent.com/u/343369?v=4","gravatar_id":"","url":"https://api.github.com/users/sfdye","html_url":"https://github.com/sfdye","followers_url":"https://api.github.com/users/sfdye/followers","following_url":"https://api.github.com/users/sfdye/following{/other_user}","gists_url":"https://api.github.com/users/sfdye/gists{/gist_id}","starred_url":"https://api.github.com/users/sfdye/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sfdye/subscriptions","organizations_url":"https://api.github.com/users/sfdye/orgs","repos_url":"https://api.github.com/users/sfdye/repos","events_url":"https://api.github.com/users/sfdye/events{/privacy}","received_events_url":"https://api.github.com/users/sfdye/received_events","type":"User","site_admin":false}],"teams":[{"name":"pygithub-owners","id":585225,"slug":"pygithub-owners","description":"","privacy":"closed","url":"https://api.github.com/teams/585225","members_url":"https://api.github.com/teams/585225/members{/member}","repositories_url":"https://api.github.com/teams/585225/repos","permission":"pull"}]}
https
DELETE
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'Content-Type': 'application/json', 'User-Agent': 'PyGithub/Python'}
{"reviewers":"sfdye"}
204
''
https
GET
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '318'), ('server', 'nginx'), ('last-modified', 'Sat, 03 Nov 2012 08:19:40 GMT'), ('connection', 'keep-alive'), ('etag', '"1ec7d9f2ebb27db7dc002f1382d23975"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 03 Nov 2012 08:19:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"users":[],"teams":[{"name":"pygithub-owners","id":585225,"slug":"pygithub-owners","description":"","privacy":"closed","url":"https://api.github.com/teams/585225","members_url":"https://api.github.com/teams/585225/members{/member}","repositories_url":"https://api.github.com/teams/585225/repos","permission":"pull"}]}
https
GET
api.github.com
None
/repos/jacquev6/PyGithub/pulls/31/requested_reviewers
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
None
200
[('status', '200 OK'), ('x-ratelimit-remaining', '4985'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('x-ratelimit-limit', '5000'), ('vary', 'Accept, Authorization, Cookie'), ('content-length', '318'), ('server', 'nginx'), ('last-modified', 'Sat, 03 Nov 2012 08:19:40 GMT'), ('connection', 'keep-alive'), ('etag', '"1ec7d9f2ebb27db7dc002f1382d23975"'), ('cache-control', 'private, s-maxage=60, max-age=60'), ('date', 'Sat, 03 Nov 2012 08:19:46 GMT'), ('content-type', 'application/json; charset=utf-8')]
{"users":[],"teams":[{"name":"pygithub-owners","id":585225,"slug":"pygithub-owners","description":"","privacy":"closed","url":"https://api.github.com/teams/585225","members_url":"https://api.github.com/teams/585225/members{/member}","repositories_url":"https://api.github.com/teams/585225/repos","permission":"pull"}]}
File diff suppressed because one or more lines are too long