Skip to content

Commit 73fe19d

Browse files
committed
Determine when something is a review more thoroughly
1 parent 8eb811a commit 73fe19d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

github_bot.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,36 @@ def handle_review_event(self, data):
305305
review_id = int(review_id[1])
306306

307307
actually_a_review = False
308+
found_comment = False
308309
for page in range(1, 100): # Assume no more than 10k comments
309310
comment_list_url = f"https://api.github.com/repos/{repo_name}/pulls/{pr['number']}/comments?per_page=100&page={page}"
310311
comment_list = requests.get(comment_list_url, headers=self.headers)
311312
comment_list.raise_for_status()
312313
comments = comment_list.json()
313314
for comment in comments:
314315
if comment["pull_request_review_id"] == review_id:
316+
found_comment = True
315317
if comment.get("in_reply_to_id") is None:
316318
actually_a_review = True
317319
if len(comments) < 100:
318320
break
319-
if not actually_a_review:
321+
for page in range(1, 100):
322+
review_list_url = f"https://api.github.com/repos/{repo_name}/pulls/{pr['number']}/reviews?per_page=100&page={page}"
323+
review_list = requests.get(review_list_url, headers=self.headers)
324+
review_list.raise_for_status()
325+
reviews = review_list.json()
326+
for review in reviews:
327+
if review["id"] == review_id:
328+
if len(review["body"]) != 0:
329+
actually_a_review = True
330+
if len(comments) < 100:
331+
break
332+
if found_comment and not actually_a_review:
333+
# Github treats any comment on a PR diff as a "review", but doesn't treat the
334+
# content in the review comment as a comment. Thus, we search through comments to
335+
# see if there's any new comments in the review (i.e. that aren't in-reply-to
336+
# anything) and ignore any reviews which do not have any fresh comments and do not
337+
# have a review "body" (which is always empty for comment "reviews").
320338
self.logger.info(f"Concluded that reivew id {review_id} is not a real review. It is theoretically at {review_web_url}")
321339
return
322340

0 commit comments

Comments
 (0)