Code review bodies are optional in some cases. (#1169)

* Code review bodies are optional in some cases.

* Add test for approving PRs without body set.
This commit is contained in:
Olof-Joachim Frahm (欧雅福)
2019-09-20 11:00:07 +10:00
committed by Steve Kowalik
parent 2df7269a95
commit b84d9b1928
5 changed files with 68 additions and 3 deletions
+4 -3
View File
@@ -422,7 +422,7 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
)
return github.IssueComment.IssueComment(self._requester, headers, data, completed=True)
def create_review(self, commit=github.GithubObject.NotSet, body=None, event=github.GithubObject.NotSet, comments=github.GithubObject.NotSet):
def create_review(self, commit=github.GithubObject.NotSet, body=github.GithubObject.NotSet, event=github.GithubObject.NotSet, comments=github.GithubObject.NotSet):
"""
:calls: `POST /repos/:owner/:repo/pulls/:number/reviews <https://developer.github.com/v3/pulls/reviews/>`_
:param commit: github.Commit.Commit
@@ -432,13 +432,14 @@ class PullRequest(github.GithubObject.CompletableGithubObject):
:rtype: :class:`github.PullRequestReview.PullRequestReview`
"""
assert commit is github.GithubObject.NotSet or isinstance(commit, github.Commit.Commit), commit
assert isinstance(body, str), body
assert body is github.GithubObject.NotSet or isinstance(body, str), body
assert event is github.GithubObject.NotSet or isinstance(event, str), event
assert comments is github.GithubObject.NotSet or isinstance(comments, list), comments
post_parameters = dict()
if commit is not github.GithubObject.NotSet:
post_parameters['commit_id'] = commit.sha
post_parameters['body'] = body
if body is not github.GithubObject.NotSet:
post_parameters['body'] = body
post_parameters['event'] = 'COMMENT' if event == github.GithubObject.NotSet else event
if comments is github.GithubObject.NotSet:
post_parameters['comments'] = []
+2
View File
@@ -128,3 +128,5 @@ from .Issue572 import *
from .Issue937 import *
from .Issue945 import *
from .Issue823 import *
from .PullRequest1169 import *
+40
View File
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
############################ Copyrights and license ############################
# #
# Copyright 2019 Olof-Joachim Frahm <olof@macrolet.net> #
# #
# 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/>. #
# #
################################################################################
from __future__ import absolute_import
from . import Framework
import datetime
class PullRequest1169(Framework.TestCase):
def setUp(self):
Framework.TestCase.setUp(self)
ferada_repo = self.g.get_repo("coleslaw-org/coleslaw", lazy=True)
self.pull = ferada_repo.get_pull(173)
def testReviewApproveWithoutBody(self):
r = self.pull.create_review(event="APPROVE")
self.assertEqual(r.id, 261942907)
self.assertEqual(r.user.login, "Ferada")
File diff suppressed because one or more lines are too long
@@ -0,0 +1,11 @@
https
POST
api.github.com
None
/repos/coleslaw-org/coleslaw/pulls/173/reviews
{'Content-Type': 'application/json', 'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
{"event": "APPROVE", "comments": []}
200
[('Date', 'Mon, 15 Jul 2019 16:42:30 GMT'), ('Content-Type', 'application/json; charset=utf-8'), ('Transfer-Encoding', 'chunked'), ('Server', 'GitHub.com'), ('Status', '200 OK'), ('X-RateLimit-Limit', '5000'), ('X-RateLimit-Remaining', '4995'), ('X-RateLimit-Reset', '1563212378'), ('Cache-Control', 'private, max-age=60, s-maxage=60'), ('Vary', 'Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding'), ('ETag', 'W/"c3218e799d214a96e76516cd1b66719c"'), ('X-OAuth-Scopes', 'notifications, public_repo'), ('X-Accepted-OAuth-Scopes', ''), ('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'), ('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', '9692:A1DA:7E28EE2:9C4D530:5D2CACF5')]
{"id":261942907,"node_id":"MDE3OlB1bGxSZXF1ZXN0UmV2aWV3MjYxOTQyOTA3","user":{"login":"Ferada","id":13713,"node_id":"MDQ6VXNlcjEzNzEz","avatar_url":"https://avatars1.githubusercontent.com/u/13713?v=4","gravatar_id":"","url":"https://api.github.com/users/Ferada","html_url":"https://github.com/Ferada","followers_url":"https://api.github.com/users/Ferada/followers","following_url":"https://api.github.com/users/Ferada/following{/other_user}","gists_url":"https://api.github.com/users/Ferada/gists{/gist_id}","starred_url":"https://api.github.com/users/Ferada/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Ferada/subscriptions","organizations_url":"https://api.github.com/users/Ferada/orgs","repos_url":"https://api.github.com/users/Ferada/repos","events_url":"https://api.github.com/users/Ferada/events{/privacy}","received_events_url":"https://api.github.com/users/Ferada/received_events","type":"User","site_admin":false},"body":"","state":"APPROVED","html_url":"https://github.com/coleslaw-org/coleslaw/pull/173#pullrequestreview-261942907","pull_request_url":"https://api.github.com/repos/coleslaw-org/coleslaw/pulls/173","author_association":"CONTRIBUTOR","_links":{"html":{"href":"https://github.com/coleslaw-org/coleslaw/pull/173#pullrequestreview-261942907"},"pull_request":{"href":"https://api.github.com/repos/coleslaw-org/coleslaw/pulls/173"}},"submitted_at":"2019-07-15T16:42:30Z","commit_id":"8492120a51c13d713c8a9121f079de2220190ce5"}