10000 Merge pull request #290 from adrianmoisey/0.9.x-review-comment · danpalmer/github3.py@0054a3d · GitHub
[go: up one dir, main page]

Skip to content

Commit 0054a3d

Browse files
committed
Merge pull request sigmavirus24#290 from adrianmoisey/0.9.x-review-comment
Add review comment
2 parents 4ea647e + 5aac0fa commit 0054a3d

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

github3/pulls.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def __init__(self, pull, session=None):
179179
#: Review comment URL Template. Expands with ``number``
180180
self.review_comment_url = URITemplate(comments) if comments else None
181181
#: Number of review comments on the pull request
182-
self.review_comments = pull.get('review_comments')
182+
self.review_comments_count = pull.get('review_comments')
183183
#: GitHub.com url for review comments (not a template)
184184
self.review_comments_url = pull.get('review_comments_url')
185185

@@ -218,6 +218,25 @@ def close(self):
218218
"""
219219
return self.update(self.title, self.body, 'closed')
220220

221+
@requires_auth
222+
def create_review_comment(self, body, commit_id, path, position):
223+
"""Create a review comment on this pull request.
224+
225+
All parameters are required by the GitHub API.
226+
227+
:param str body: The comment text itself
228+
:param str commit_id: The SHA of the commit to comment on
229+
:param str path: The relative path of the file to comment on
230+
:param int position: The line index in the diff to comment on.
231+
:returns: The created review comment.
232+
:rtype: :class:`~github3.pulls.ReviewComment`
233+
"""
234+
url = self._build_url('comments', base_url=self._api)
235+
data = {'body': body, 'commit_id': commit_id, 'path': path,
236+
'position': str(position)}
237+
json = self._json(self._post(url, data=data), 201)
238+
return ReviewComment(json, self) if json else None
239+
221240
def diff(self):
222241
"""Return the diff"""
223242
resp = self._get(self._api,
@@ -310,6 +329,17 @@ def reopen(self):
310329
"""
311330
return self.update(self.title, self.body, 'open')
312331

332+
def review_comments(self, number=-1, etag=None):
333+
r"""Iterate over the review comments on this pull request.
334+
:param int number: (optional), number of comments to return. Default:
335+
-1 returns all available comments.
336+
:param str etag: (optional), ETag from a previous request to the same
337+
endpoint
338+
:returns: generator of :class:`ReviewComment <ReviewComment>`\ s
339+
"""
340+
url = self._build_url('comments', base_url=self._api)
341+
return self._iter(int(number), url, ReviewComment, etag=etag)
342+
313343
@requires_auth
314344
def update(self, title=None, body=None, state=None):
315345
"""Update this pull request.
@@ -374,5 +404,24 @@ def __init__(self, comment, session=None):
374404
#: Original commit SHA
375405
self.original_commit_id = comment.get('original_commit_id')
376406

407+
#: API URL for the Pull Request
408+
self.pull_request_url = comment.get('pull_request_url')
409+
377410
def _repr(self):
378411
return '<Review Comment [{0}]>'.format(self.user.login)
412+
413+
@requires_auth
414+
def reply(self, body):
415+
"""Reply to this review comment with a new review comment.
416+
417+
:param str body: The text of the comment.
418+
:returns: The created review comment.
419+
:rtype: :class:`~github3.pulls.ReviewComment`
420+
"""
421+
url = self._build_url('comments', base_url=self.pull_request_url)
422+
index = self._api.rfind('/') + 1
423+
in_reply_to = self._api[index:]
424+
json = self._json(self._post(url, data={
425+
'body': body, 'in_reply_to': in_reply_to
426+
}), 201)
427+
return ReviewComment(json, self) if json else None
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0b1", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA62YTZOjNhCG/4qLazyWMeOZXapSm5yS3PawueTiEiAb1QCiJGGXh5r/nrcRGOyt+GOUi8vG6kevWt2iW20gsyCOXsPlaxjOg4qXIoiDnbR5k0SL+hjMg21TFJv+DyN3Jd9L3ZjVMzsbpQ6V0EHcBoXayQqM6VBQaJrV8/JLtJwHfM8t15tGFxiXW1ubmDH30CwctTFCp6qyorKLVJWsYc742/7XFWg73TMIG+DB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UtVU2JBV+HUeHLhF8Yp37/ThUEmcuj6am5uNy9MgtrqhthJPxnNg8vAg3+TYfGIUaTaDmWvj+uleX3FuSq1Vf0NUIW1xA1CLqp9s1OVaSWDIZjKCFjKuo19WJra8KezGldNYR4Y+oFA1xZLQJRZCVxV0hdX3zm5JFGeDTjpB3He01JWwB3SPgxqSMC1c+tWErx//AoMNcx5kEwAA", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "a8d8e492d6966f0c23dee2eed64c678a", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"be9168b0280eb86a632ad8c59e025808\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4940", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, 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": "48A0B008:2E0E:362D765:544D5532", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Wed, 22 Oct 2014 05:56:31 GMT", "date": "Sun, 26 Oct 2014 20:10:26 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": "1414357215"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py"}, "recorded_at": "2014-10-26T20:10:26"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0b1", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/pulls/286"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+1bXW/rNhL9K4L6sou1LUuyY8dI0y12gd0+tdi992WbwqAlyiYiS4JEOfUV7n/fM6Qky3biOGGK3gchSBDT5OFwOPyYM5zKLvPYXtgbKbNi4TgsE6O1kJtyNQrSrZPzLC2cQqy3bCfysvAmjv7WH2V7JyvjuHC8+Y09sEVoLzzfn05mM28AuG28PEbuoF7Cq+FCEUXvBxhRcwiVMRlsDGBUexpcUZT8BOdNmlIAjaqScrviOdQ1vxnYhWSSYwLSjCfoKU6DRw5VRiwu+MCWQsb07Y9haIlESMFiK2NFYUVpbgU5Z1IkayvnO8GfLEzYlieyAExZUAcV4NYiQfuuxpvJmozn/nhgsx2TLD8dnCosalMgtCBNJMCVVZSOpxr/sPveA9o6rzHIBmzq/ZJJEdixSaHF9faCylEax+kTUE6FPrbd846ctmWLAvW9EwUtKyeVGw7dYUhfSRGikG8XSrWqsK4KuRQh4cAm8pyHbxasbgexnhJIVKnlqwDLVRHkIpMiTd4u4FFroKX5miXiC2zvPWhoTRaqdpY3j1C1Qmu+I0N/c3PdrHKyXOxYsCfV5DzgYgdlvxPypD0Q5T6jJfuZliBULyRfsnBLy1At6q8De5WGe9T4L+fWd958ohbzNs05VjAW2e9y9JA/JPT76ed//rxoPgwt2gUkh7VQkWUNrV+t36yf0AQrkCajW/wZu0WnJa0Yi+zUkqn1K9QY73/7S7Pphxh7jA0o7279O7/e35ttxflObTh8yIZ10V8JjGFDyqUIypjlJzuRGkcjJwm/5XKTYgyp9R+1Zf1D71iWiKwsZwFQWNy0ORnsi8NtvqABQ99axnDJJDTsjd3J0B0PvZtP7u3CnS0ms/+hTpmFGMflOkGcFnWVBMfcwN7yfH1esCRVCLksNoz682auP2Yz72Z6O+XT+e10gr/Mm02ms3F0E81C92YeugFkwCYu1gmHpdTwIsbMpklboIFfsfErz2enBlP2TopXYr++hN4CX588x/iXV+g18K31VfrYpDX7E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BJap5LAPdAqfxKM4OJ+oRTIXTTPlhTXdzWbYN0Wep3X0WAcyKJBdd3aQS7uSgKE2nRo0kMM46m 53E6 GFPGJlLJf6Oo1x1PEp+yvFzmDmF5lyFmeIxXQJ8qZE8+J87PLbMPJAwLszhGb8wGPj6SQKxmEUuPidBzf+rT8DRM+L97x4H0U/Y0q/kSh6z4tf+8YKW1n/ZoYuE89EZPo3M91HH88o6BtZ7T0v/vwbzJ4X73lxQ56058VrF7Tnxd8f43PaZ089L97z4rJ+F2lESIFW6Xnxk5SL+hl+0fPiPS9O7Fv9aNhonfW8+MUsp54Xbx40XibVi54X19z8n8KLL2OR4FkP3okWPMbT8Mre6Cfihpl9oNzpCdozgK9HPVQCiUroA4qKPzwD8948OkA2weePQz3kAgD+JFXCtJc2W/JCJx/Tx3lQvlYW3j98TA+Y0zanBNjN3d8U/O2pEyokhHSqpTZS+y67p7SqO2aR+X//0Ca2XmGt9ZMGZGQ92FYQwy1Ge1U4pMWFQpWOicLPCVvFnPKYdJD0NAPzwb6nxK47h92fJ3fdOdk90rsSiKryu9rPZdz2KlnxiE4LCSTUjAX9ze7bnKir2pyjDZGMttWQIslKaVGuGsaDKGLwuEp/74y7lUC1GXZqhKKg0Yf33dSzO0fLGIs/vFdK9Gq6c8qYNNN2XqvpKNvt3Bbem+8GzSHoEO/VvL6S+vZtzNC1SXcdDR7y7shGL9nkHz7TndTGb8K+jq2NPoE4UrsPZW0iUH0hoxPK1Nmc+Id+jtRMBUeJnPRZZXA2tY8sWhnhawbYNFVZo1clXl4pE8ascyHbZwLqI+0JzTOBtmBJOzo9eQjwPoXy2+ssyhXyX/VzgcMZjlz0sxMXZVRBnVt4KMDCEDnwyDrGJ7x/CPHqpf5IFTd4iImHJhE5Rajw9f90DA4P3EAAAA==", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP, Accept-Encoding", "x-served-by": "6d7de9e645814cac34ea2a8d72ba3141", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"fcf9b69c952193a9a135840c1d2498e8\"", "access-control-allow-credentials": "true", "status": "200 OK", "x-ratelimit-remaining": "4939", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, 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": "48A0B008:2E0E:362D7A2:544D5532", "cache-control": "private, max-age=60, s-maxage=60", "last-modified": "Sun, 26 Oct 2014 19:17:47 GMT", "date": "Sun, 26 Oct 2014 20:10:26 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": "1414357215"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/pulls/286"}, "recorded_at": "2014-10-26T20:10:26"}, {"request": {"body": {"string": "{\"body\": \"Testing review comments\", \"commit_id\": \"4437428aefdb50913e2acabd0552bd13021dc38f\", \"position\": \"6\", \"path\": \"github3/pulls.py\"}", "encoding": "utf-8"}, "headers": {"Content-Length": "137", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.v3.full+json", "User-Agent": "github3.py/1.0.0b1", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Authorization": "Basic <BASIC_AUTH>"}, "method": "POST", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/pulls/286/comments"}, "response": {"body": {"string": "{\"url\":\"https://api.github.com/repos/sigmavirus24/github3.py/pulls/comments/19383389\",\"id\":19383389,\"diff_hunk\":\"@@ -195,6 +195,25 @@ def close(self):\\n \\\"\\\"\\\"\\n return self.update(self.title, self.body, 'closed')\\n \\n+ @requires_auth\\n+ def create_review_comment(self, body, commit_id, path, position):\\n+ \\\"\\\"\\\"Create a review comment on this pull request.\",\"path\":\"github3/pulls.py\",\"position\":6,\"original_position\":6,\"commit_id\":\"4437428aefdb50913e2acabd0552bd13021dc38f\",\"original_commit_id\":\"4437428aefdb50913e2acabd0552bd13021dc38f\",\"user\":{\"login\":\"sigmavirus24\",\"id\":240830,\"avatar_url\":\"https://avatars.githubusercontent.com/u/240830?v=2\",\"gravatar_id\":\"\",\"url\":\"https://api.github.com/users/sigmavirus24\",\"html_url\":\"https://github.com/sigmavirus24\",\"followers_url\":\"https://api.github.com/users/sigmavirus24/followers\",\"following_url\":\"https://api.github.com/users/sigmavirus24/following{/other_user}\",\"gists_url\":\"https://api.github.com/users/sigmavirus24/gists{/gist_id}\",\"starred_url\":\"https://api.github.com/users/sigmavirus24/starred{/owner}{/repo}\",\"subscriptions_url\":\"https://api.github.com/users/sigmavirus24/subscriptions\",\"organizations_url\":\"https://api.github.com/users/sigmavirus24/orgs\",\"repos_url\":\"https://api.github.com/users/sigmavirus24/repos\",\"events_url\":\"https://api.github.com/users/sigmavirus24/events{/privacy}\",\"received_events_url\":\"https://api.github.com/users/sigmavirus24/received_events\",\"type\":\"User\",\"site_admin\":false},\"body\":\"Testing review comments\",\"created_at\":\"2014-10-26T20:10:26Z\",\"updated_at\":\"2014-10-26T20:10:26Z\",\"html_url\":\"https://github.com/sigmavirus24/github3.py/pull/286#discussion_r19383389\",\"pull_request_url\":\"https://api.github.com/repos/sigmavirus24/github3.py/pulls/286\",\"_links\":{\"self\":{\"href\":\"https://api.github.com/repos/sigmavirus24/github3.py/pulls/comments/19383389\"},\"html\":{\"href\":\"https://github.com/sigmavirus24/github3.py/pull/286#discussion_r19383389\"},\"pull_request\":{\"href\":\"https://api.github.com/repos/sigmavirus24/github3.py/pulls/286\"}},\"body_html\":\"<p>Testing review comments</p>\",\"body_text\":\"Testing review comments\"}", "encoding": "utf-8"}, "headers": {"content-length": "2139", "vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "etag": "\"716d9f12bb65c27bda6188757c89e7df\"", "location": "https://api.github.com/repos/sigmavirus24/github3.py/pulls/comments/19383389", "access-control-allow-credentials": "true", "status": "201 Created", "x-ratelimit-remaining": "4938", "x-github-media-type": "github.v3; param=full; format=json", "access-control-expose-headers": "ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval", "x-github-request-id": "48A0B008:2E0E:362D7D4:544D5532", "cache-control": "private, max-age=60, s-maxage=60", "date": "Sun, 26 Oct 2014 20:10:26 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "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": "1414357215"}, "status": {"message": "Created", "code": 201}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/pulls/286/comments"}, "recorded_at": "2014-10-26T20:10:26"}], "recorded_with": "betamax/0.4.1"}

0 commit comments

Comments
 (0)
0