Skip to content

Commit 59996a8

Browse files
committed
Don't handle nested review comments
1 parent 120bff3 commit 59996a8

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

bot/github.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,25 @@ def pull_request_review(self, update, context):
171171
author = review['user']
172172
repo = update.payload['repository']
173173

174+
# Warning: Currently only works for public repos. Otherwise, we need an access token
175+
# to access the comments.
176+
comments = github_api.get_pull_request_review_comments(
177+
repo['owner']['login'],
178+
repo['name'],
179+
pull_request['number'],
180+
review['id'],
181+
)
182+
all_replies = all(comment.get("in_reply_to_id") for comment in comments)
183+
174184
if review['body']:
175185
text = "\n\n" + render_github_markdown(review['body'], repo['full_name'])
176186
else:
177187
text = ""
178188

189+
if not text and all_replies:
190+
# Don't ping when review only contains replies
191+
return
192+
179193
review_link = link(review['html_url'],
180194
f'{repo["full_name"]}#{pull_request["number"]} {pull_request["title"]}')
181195
author_link = link(author['html_url'], '@' + author['login'])
@@ -200,9 +214,6 @@ def pull_request_review_comment(self, update, context):
200214
if update.payload['action'] == 'created':
201215
pull_request = update.payload['pull_request']
202216
comment = update.payload['comment']
203-
if comment.get('in_reply_to_id'):
204-
# Don't handle comments that are replies to other comments
205-
return
206217

207218
author = comment['user']
208219
repo = update.payload['repository']

bot/githubapi.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,22 @@ def get(self, url, *args, api=True, jwt_bearer=False, oauth_server_auth=None, ac
8181
def get_paginated(self, key, url, *args, **kwargs):
8282
r = self.get(url, *args, **kwargs)
8383
r.raise_for_status()
84-
data = r.json()[key]
84+
85+
json_data = r.json()
86+
if isinstance(json_data, list):
87+
data = json_data
88+
else:
89+
data = json_data[key]
90+
8591
while 'link' in r.links.keys():
8692
r = self.get(url, headers=r.request.headers)
8793
r.raise_for_status()
88-
data.extend(r.json()[key])
94+
95+
json_data = r.json()
96+
if isinstance(json_data, list):
97+
data.extend(json_data)
98+
else:
99+
data.extend(json_data[key])
89100
return data
90101

91102
def oauth_authorize_url(self, *args):
@@ -141,6 +152,14 @@ def get_repository(self, repo_id, access_token):
141152

142153
return r.json()
143154

155+
def get_pull_request_review_comments(self, owner, repo, pull_number, review_id, *args, **kwargs):
156+
return self.get_paginated(
157+
'comments',
158+
f'https://api.github.com/repos/{owner}/{repo}/pulls/{pull_number}/reviews/{review_id}/comments',
159+
*args,
160+
**kwargs
161+
)
162+
144163
def markdown(self, markdown, context):
145164
r = self.post(f'https://api.github.com/markdown', json={
146165
'text': markdown,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy