@@ -11,8 +11,9 @@ import (
11
11
)
12
12
13
13
func TestNotificationState (t * testing.T ) {
14
- firstCoreReviewer := membership .AvailableReviewers ()[0 ]
15
- secondCoreReviewer := membership .AvailableReviewers ()[1 ]
14
+ availableReviewers := membership .AvailableReviewers ()
15
+ firstCoreReviewer := availableReviewers [0 ]
16
+ secondCoreReviewer := availableReviewers [1 ]
16
17
cases := map [string ]struct {
17
18
pullRequest * github.PullRequest
18
19
issueEvents []* github.IssueEvent
@@ -442,6 +443,183 @@ func TestNotificationState(t *testing.T) {
442
443
expectState : waitingForMerge ,
443
444
expectSince : time .Date (2024 , 2 , 1 , 0 , 0 , 0 , 0 , time .UTC ),
444
445
},
446
+ "ready_for_review event after creation" : {
447
+ pullRequest : & github.PullRequest {
448
+ User : & github.User {Login : github .String ("author" )},
449
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
450
+ },
451
+ issueEvents : []* github.IssueEvent {
452
+ & github.IssueEvent {
453
+ Event : github .String ("review_requested" ),
454
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
455
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
456
+ },
457
+ & github.IssueEvent {
458
+ Event : github .String ("ready_for_review" ),
459
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
460
+ },
461
+ },
462
+ expectState : waitingForReview ,
463
+ expectSince : time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC ),
464
+ },
465
+
466
+ "ready_for_review event before review request" : {
467
+ pullRequest : & github.PullRequest {
468
+ User : & github.User {Login : github .String ("author" )},
469
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
470
+ },
471
+ issueEvents : []* github.IssueEvent {
472
+ & github.IssueEvent {
473
+ Event : github .String ("ready_for_review" ),
474
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
475
+ },
476
+ & github.IssueEvent {
477
+ Event : github .String ("review_requested" ),
478
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
479
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
480
+ },
481
+ },
482
+ expectState : waitingForReview ,
483
+ expectSince : time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC ),
484
+ },
485
+
486
+ "review after ready_for_review" : {
487
+ pullRequest : & github.PullRequest {
488
+ User : & github.User {Login : github .String ("author" )},
489
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
490
+ },
491
+ issueEvents : []* github.IssueEvent {
492
+ & github.IssueEvent {
493
+ Event : github .String ("ready_for_review" ),
494
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
495
+ },
496
+ & github.IssueEvent {
497
+ Event : github .String ("review_requested" ),
498
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
499
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
500
+ },
501
+ },
502
+ reviews : []* github.PullRequestReview {
503
+ & github.PullRequestReview {
504
+ User : & github.User {Login : github .String (firstCoreReviewer )},
505
+ State : github .String ("APPROVED" ),
506
+ SubmittedAt : & github.Timestamp {time .Date (2024 , 1 , 4 , 0 , 0 , 0 , 0 , time .UTC )},
507
+ },
508
+ },
509
+ expectState : waitingForMerge ,
510
+ expectSince : time .Date (2024 , 1 , 4 , 0 , 0 , 0 , 0 , time .UTC ),
511
+ },
512
+ "changes_requested after ready_for_review" : {
513
+ pullRequest : & github.PullRequest {
514
+ User : & github.User {Login : github .String ("author" )},
515
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
516
+ },
517
+ issueEvents : []* github.IssueEvent {
518
+ & github.IssueEvent {
519
+ Event : github .String ("review_requested" ),
520
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )}, // Earlier request
521
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
522
+ },
523
+ & github.IssueEvent {
524
+ Event : github .String ("ready_for_review" ),
525
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
526
+ },
527
+ },
528
+ reviews : []* github.PullRequestReview {
529
+ & github.PullRequestReview {
530
+ User : & github.User {Login : github .String (firstCoreReviewer )},
531
+ State : github .String ("CHANGES_REQUESTED" ),
532
+ SubmittedAt : & github.Timestamp {time .Date (2024 , 1 , 4 , 0 , 0 , 0 , 0 , time .UTC )}, // Early changes requested
533
+ },
534
+ },
535
+ expectState : waitingForContributor ,
536
+ expectSince : time .Date (2024 , 1 , 4 , 0 , 0 , 0 , 0 , time .UTC ), // Should use ready_for_review time
537
+ },
538
+
539
+ "changes_requested before ready_for_review" : {
540
+ pullRequest : & github.PullRequest {
541
+ User : & github.User {Login : github .String ("author" )},
542
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
543
+ },
544
+ issueEvents : []* github.IssueEvent {
545
+ & github.IssueEvent {
546
+ Event : github .String ("review_requested" ),
547
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
548
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
549
+ },
550
+ & github.IssueEvent {
551
+ Event : github .String ("ready_for_review" ),
552
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )}, // Earlier ready
553
+ },
554
+ },
555
+ reviews : []* github.PullRequestReview {
556
+ & github.PullRequestReview {
557
+ User : & github.User {Login : github .String (firstCoreReviewer )},
558
+ State : github .String ("CHANGES_REQUESTED" ),
559
+ SubmittedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
560
+ },
561
+ },
562
+ expectState : waitingForContributor ,
563
+ expectSince : time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC ), // Should use changes requested time since it's later
564
+ },
565
+
566
+ "comment review after ready_for_review" : {
567
+ pullRequest : & github.PullRequest {
568
+ User : & github.User {Login : github .String ("author" )},
569
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
570
+ },
571
+ issueEvents : []* github.IssueEvent {
572
+ & github.IssueEvent {
573
+ Event : github .String ("ready_for_review" ),
574
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
575
+ },
576
+ & github.IssueEvent {
577
+ Event : github .String ("review_requested" ),
578
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
579
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
580
+ },
581
+ },
582
+ reviews : []* github.PullRequestReview {
583
+ & github.PullRequestReview {
584
+ User : & github.User {Login : github .String (firstCoreReviewer )},
585
+ State : github .String ("COMMENTED" ),
586
+ SubmittedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
587
+ },
588
+ },
589
+ expectState : waitingForContributor ,
590
+ expectSince : time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC ), // Should use ready_for_review time
591
+ },
592
+
593
+ "multiple ready_for_review events" : {
594
+ pullRequest : & github.PullRequest {
595
+ User : & github.User {Login : github .String ("author" )},
596
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 1 , 0 , 0 , 0 , 0 , time .UTC )},
597
+ },
598
+ issueEvents : []* github.IssueEvent {
599
+ & github.IssueEvent {
600
+ Event : github .String ("ready_for_review" ),
601
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 2 , 0 , 0 , 0 , 0 , time .UTC )},
602
+ },
603
+ & github.IssueEvent {
604
+ Event : github .String ("review_requested" ),
605
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 3 , 0 , 0 , 0 , 0 , time .UTC )},
606
+ RequestedReviewer : & github.User {Login : github .String (firstCoreReviewer )},
607
+ },
608
+ & github.IssueEvent {
609
+ Event : github .String ("ready_for_review" ),
610
+ CreatedAt : & github.Timestamp {time .Date (2024 , 1 , 5 , 0 , 0 , 0 , 0 , time .UTC )}, // Later ready_for_review
611
+ },
612
+ },
613
+ reviews : []* github.PullRequestReview {
614
+ & github.PullRequestReview {
615
+ User : & github.User {Login : github .String (firstCoreReviewer )},
616
+ State : github .String ("CHANGES_REQUESTED" ),
617
+ SubmittedAt : & github.Timestamp {time .Date (2024 , 1 , 4 , 0 , 0 , 0 , 0 , time .UTC )},
618
+ },
619
+ },
620
+ expectState : waitingForContributor ,
621
+ expectSince : time .Date (2024 , 1 , 5 , 0 , 0 , 0 , 0 , time .UTC ), // Should use latest ready_for_review time
622
+ },
445
623
}
446
624
447
625
for tn , tc := range cases {
@@ -786,8 +964,9 @@ func TestShouldNotify(t *testing.T) {
786
964
}
787
965
788
966
func TestFormatReminderComment (t * testing.T ) {
789
- firstCoreReviewer := membership .AvailableReviewers ()[0 ]
790
- secondCoreReviewer := membership .AvailableReviewers ()[1 ]
967
+ availableReviewers := membership .AvailableReviewers ()
968
+ firstCoreReviewer := availableReviewers [0 ]
969
+ secondCoreReviewer := availableReviewers [1 ]
791
970
cases := map [string ]struct {
792
971
pullRequest * github.PullRequest
793
972
state pullRequestReviewState
0 commit comments