@@ -316,6 +316,55 @@ def createStatus(
316
316
)
317
317
return None
318
318
319
+ # Users could reference wrong PRs in commit messages.
320
+ # So, to make sure we are commenting the correct one we need to check
321
+ # if the given commit is actually corresponding to the PR we parsed
322
+ # from the commit message.
323
+
324
+ wrong_issue = True
325
+ page = 1
326
+ while wrong_issue :
327
+ events_response = yield self ._http .get (
328
+ "/" .join (["/repos" , repo_user , repo_name , "issues" , issue , "events" ]) +
329
+ f"?per_page=100&page={ page } " )
330
+ if events_response .code not in (200 ,):
331
+ log .msg (
332
+ f"LLVMFailGitHubReporter.createStatus: WARNING: Cannot get events for PR#{ issue } . Do not comment this PR."
333
+ )
334
+ return None
335
+
336
+ events = yield events_response .json ()
337
+
338
+ # Empty events array signals that there is no more.
339
+ if not events :
340
+ log .msg (
341
+ f"LLVMFailGitHubReporter.createStatus: WARNING: Got empty events list for PR#{ issue } ."
342
+ )
343
+ break
344
+
345
+ log .msg (
346
+ "LLVMFailGitHubReporter.createStatus: WARNING: Got events list for PR#{issue} (page {page}): {events}."
347
+ )
348
+
349
+ for event in events :
350
+ if event ["event" ] == "merged" :
351
+ if event ["commit_id" ] == sha :
352
+ wrong_issue = False
353
+ break
354
+ else :
355
+ log .msg (
356
+ f"LLVMFailGitHubReporter.createStatus: WARNING: Event 'merged' in PR#{ issue } contains commit_id { event ['commit_id' ]} , but revision is { sha } ."
357
+ )
358
+ page += 1
359
+
360
+ if wrong_issue :
361
+ log .msg (
362
+ f"LLVMFailGitHubReporter.createStatus: WARNING: Given commit { sha } is not related to PR#{ issue } . Do not comment this PR."
363
+ )
364
+ return None
365
+
366
+ # This is the right issue to comment.
367
+
319
368
url = "/" .join (["/repos" , repo_user , repo_name , "issues" , issue , "comments" ])
320
369
log .msg (f"LLVMFailGitHubReporter.createStatus: INFO: http.post({ url } )" )
321
370
0 commit comments