@@ -339,6 +339,11 @@ def process_event(self, event):
339
339
applied as a result of this event.
340
340
"""
341
341
342
+ # TODO: Don't hardcode botname!
343
+ botname = 'bors'
344
+ # TODO: Don't hardcode hooks!
345
+ hooks = []
346
+
342
347
result = ProcessEventResult ()
343
348
if event .event_type == 'PullRequestCommit' :
344
349
result .changed = self .head_sha != event ['commit' ]['oid' ]
@@ -354,14 +359,18 @@ def process_event(self, event):
354
359
result .changed = result .changed or self .approved_by != ''
355
360
self .approved_by = ''
356
361
362
+ elif event .event_type == 'BaseRefChangedEvent' :
363
+ # Base ref changed: no longer approved
364
+ result .changed = self .approved_by != ''
365
+ self .approved_by = ''
366
+
367
+
357
368
elif event .event_type == 'IssueComment' :
358
369
comments = parse_issue_comment (
359
370
username = event ['author' ]['login' ],
360
371
body = event ['body' ],
361
372
sha = self .head_sha ,
362
- # TODO: Don't hardcode 'bors'
363
- botname = 'bors' ,
364
- # TODO: Hooks!
373
+ botname = botname ,
365
374
hooks = [])
366
375
367
376
for comment in comments :
@@ -441,11 +450,13 @@ def process_issue_comment(self, event, command):
441
450
# TODO: Don't hardcode botname
442
451
botname = 'bors'
443
452
username = event ['author' ]['login' ]
453
+ # TODO: Don't hardcode repo_cfg
454
+ repo_cfg = {}
444
455
_assert_reviewer_auth_verified = functools .partial (
445
456
assert_authorized ,
446
457
username ,
447
458
self .repo_label ,
448
- {}, # repo_cfg
459
+ repo_cfg ,
449
460
self ,
450
461
AuthState .REVIEWER ,
451
462
botname ,
@@ -454,7 +465,7 @@ def process_issue_comment(self, event, command):
454
465
assert_authorized ,
455
466
username ,
456
467
self .repo_label ,
457
- {}, # repo_cfg
468
+ repo_cfg ,
458
469
self ,
459
470
AuthState .TRY ,
460
471
botname ,
@@ -542,37 +553,38 @@ def process_issue_comment(self, event, command):
542
553
.format (treeclosed )
543
554
)
544
555
545
- # elif command.action == 'unapprove':
546
- # # Allow the author of a pull request to unapprove their own PR.
547
- # # The author can already perform other actions that effectively
548
- # # unapprove the PR (change the target branch, push more
549
- # # commits, etc.) so allowing them to directly unapprove it is
550
- # # also allowed.
551
- # if state.author != username:
552
- # assert_authorized(username, repo_label, repo_cfg, state,
553
- # AuthState.REVIEWER, my_username)
554
- #
555
- # state.approved_by = ''
556
- # state.save()
557
- # if realtime:
558
- # state.change_labels(LabelEvent.REJECTED)
559
- #
560
- # elif command.action == 'prioritize':
561
- # assert_authorized(username, repo_label, repo_cfg, state,
562
- # AuthState.TRY, my_username)
563
- #
564
- # pvalue = command.priority
565
- #
566
- # if pvalue > global_cfg['max_priority']:
567
- # if realtime:
568
- # state.add_comment(
569
- # ':stop_sign: Priority higher than {} is ignored.'
570
- # .format(global_cfg['max_priority'])
571
- # )
572
- # #continue
573
- # state.priority = pvalue
574
- # state.save()
575
- #
556
+ elif command .action == 'unapprove' :
557
+ # Allow the author of a pull request to unapprove their own PR.
558
+ # The author can already perform other actions that effectively
559
+ # unapprove the PR (change the target branch, push more
560
+ # commits, etc.) so allowing them to directly unapprove it is
561
+ # also allowed.
562
+ if self .author != username :
563
+ assert_authorized (username , self .repo_label , repo_cfg , self ,
564
+ AuthState .REVIEWER , botname )
565
+
566
+ self .approved_by = ''
567
+ result .changed = True
568
+ result .label_events .append (LabelEvent .REJECTED )
569
+
570
+ elif command .action == 'prioritize' :
571
+ assert_authorized (username , self .repo_label , repo_cfg , self ,
572
+ AuthState .TRY , botname )
573
+
574
+ pvalue = command .priority
575
+
576
+ # TODO: Don't hardcode max_priority
577
+ # global_cfg['max_priority']
578
+ max_priority = 9001
579
+ if pvalue > max_priority :
580
+ result .comments .append (
581
+ ':stop_sign: Priority higher than {} is ignored.'
582
+ .format (max_priority )
583
+ )
584
+ return result
585
+ result .changed = self .priority != pvalue
586
+ self .priority = pvalue
587
+
576
588
# elif command.action == 'delegate':
577
589
# assert_authorized(username, repo_label, repo_cfg, state,
578
590
# AuthState.REVIEWER, my_username)
@@ -644,13 +656,12 @@ def process_issue_comment(self, event, command):
644
656
# # to any meaningful labeling events.
645
657
# state.change_labels(LabelEvent.TRY)
646
658
#
647
- # elif command.action == 'rollup':
648
- # _assert_try_auth_verified()
649
- #
650
- # state.rollup = command.rollup_value
651
- #
652
- # state.save()
653
- #
659
+ elif command .action == 'rollup' :
660
+ _assert_try_auth_verified ()
661
+
662
+ result .changed = self .rollup != command .rollup_value
663
+ self .rollup = command .rollup_value
664
+
654
665
# elif command.action == 'force' and realtime:
655
666
# _assert_try_auth_verified()
656
667
#
0 commit comments