@@ -37,6 +37,7 @@ pub(super) async fn command_approve(
37
37
} ;
38
38
39
39
if repo_state. config . load ( ) . wait_on_ci_approval {
40
+ tracing:: debug!( "Checking CI status for PR {}" , pr. number) ;
40
41
// Get all the check suites for the PR.
41
42
let checks = repo_state
42
43
. client
@@ -276,15 +277,15 @@ mod tests {
276
277
use crate :: {
277
278
github:: PullRequestNumber ,
278
279
tests:: mocks:: {
279
- default_pr_number, default_repo_name, run_test, BorsBuilder , BorsTester , Permissions ,
280
- PullRequestChangeEvent , User , World ,
280
+ default_pr_number, default_repo_name, run_test, BorsBuilder , BorsTester , Branch ,
281
+ Permissions , PullRequestChangeEvent , User , World ,
281
282
} ,
282
283
} ;
283
284
284
285
#[ sqlx:: test]
285
286
async fn default_approve ( pool : sqlx:: PgPool ) {
286
287
BorsBuilder :: new ( pool)
287
- . world ( create_world_with_approve_config ( ) )
288
+ . world ( create_world_with_immediate_approve_config ( ) )
288
289
. run_test ( |mut tester| async {
289
290
tester. post_comment ( "@bors r+" ) . await ?;
290
291
assert_eq ! (
@@ -310,7 +311,7 @@ mod tests {
310
311
#[ sqlx:: test]
311
312
async fn approve_on_behalf ( pool : sqlx:: PgPool ) {
312
313
BorsBuilder :: new ( pool)
313
- . world ( create_world_with_approve_config ( ) )
314
+ . world ( create_world_with_immediate_approve_config ( ) )
314
315
. run_test ( |mut tester| async {
315
316
let approve_user = "user1" ;
316
317
tester
@@ -351,7 +352,7 @@ mod tests {
351
352
#[ sqlx:: test]
352
353
async fn unapprove ( pool : sqlx:: PgPool ) {
353
354
BorsBuilder :: new ( pool)
354
- . world ( create_world_with_approve_config ( ) )
355
+ . world ( create_world_with_immediate_approve_config ( ) )
355
356
. run_test ( |mut tester| async {
356
357
tester. post_comment ( "@bors r+" ) . await ?;
357
358
assert_eq ! (
@@ -382,7 +383,7 @@ mod tests {
382
383
#[ sqlx:: test]
383
384
async fn unapprove_on_base_edited ( pool : sqlx:: PgPool ) {
384
385
BorsBuilder :: new ( pool)
385
- . world ( create_world_with_approve_config ( ) )
386
+ . world ( create_world_with_immediate_approve_config ( ) )
386
387
. run_test ( |mut tester| async {
387
388
tester. post_comment ( "@bors r+" ) . await ?;
388
389
assert_eq ! (
@@ -416,7 +417,7 @@ PR will need to be re-approved."#,
416
417
#[ sqlx:: test]
417
418
async fn edit_pr_do_nothing_when_base_not_edited ( pool : sqlx:: PgPool ) {
418
419
BorsBuilder :: new ( pool)
419
- . world ( create_world_with_approve_config ( ) )
420
+ . world ( create_world_with_immediate_approve_config ( ) )
420
421
. run_test ( |mut tester| async {
421
422
tester. post_comment ( "@bors r+" ) . await ?;
422
423
assert_eq ! (
@@ -468,7 +469,7 @@ PR will need to be re-approved."#,
468
469
#[ sqlx:: test]
469
470
async fn unapprove_on_push ( pool : sqlx:: PgPool ) {
470
471
BorsBuilder :: new ( pool)
471
- . world ( create_world_with_approve_config ( ) )
472
+ . world ( create_world_with_immediate_approve_config ( ) )
472
473
. run_test ( |mut tester| async {
473
474
tester. post_comment ( "@bors r+" ) . await ?;
474
475
assert_eq ! (
@@ -506,14 +507,96 @@ PR will need to be re-approved."#,
506
507
. await ;
507
508
}
508
509
509
- fn create_world_with_approve_config ( ) -> World {
510
+ #[ sqlx:: test]
511
+ async fn wait_for_ci_approval ( pool : sqlx:: PgPool ) {
512
+ BorsBuilder :: new ( pool)
513
+ . world ( create_world_with_ci_approved_config ( ) )
514
+ . run_test ( |mut tester| async {
515
+ tester. post_comment ( "@bors r+" ) . await ?;
516
+ assert_eq ! (
517
+ tester. get_comment( ) . await ?,
518
+ ":hourglass_flowing_sand: Waiting for CI checks to complete before approving..."
519
+ ) ;
520
+ Ok ( tester)
521
+ } )
522
+ . await ;
523
+ }
524
+
525
+ #[ sqlx:: test]
526
+ async fn reject_approval_on_failed_ci ( pool : sqlx:: PgPool ) {
527
+ BorsBuilder :: new ( pool)
528
+ . world ( create_world_with_ci_approved_config ( ) )
529
+ . run_test ( |mut tester| async {
530
+ let branch_name = format ! ( "pr-{}" , default_pr_number( ) ) ;
531
+ tester. create_branch ( & branch_name) . expect_suites ( 1 ) ;
532
+ tester
533
+ . workflow_failure ( tester. get_branch ( & branch_name) )
534
+ . await ?;
535
+ tester. post_comment ( "@bors r+" ) . await ?;
536
+ assert_eq ! (
537
+ tester. get_comment( ) . await ?,
538
+ ":x: Approval rejected, CI checks have failed."
539
+ ) ;
540
+ Ok ( tester)
541
+ } )
542
+ . await ;
543
+ }
544
+
545
+ #[ sqlx:: test]
546
+ async fn approve_on_ci_success ( pool : sqlx:: PgPool ) {
547
+ BorsBuilder :: new ( pool)
548
+ . world ( create_world_with_ci_approved_config ( ) )
549
+ . run_test ( |mut tester| async {
550
+ let branch_name = format ! ( "pr-{}" , default_pr_number( ) ) ;
551
+ tester. create_branch ( & branch_name) . expect_suites ( 1 ) ;
552
+ tester
553
+ . workflow_success ( tester. get_branch ( & branch_name) )
554
+ . await ?;
555
+ tester. post_comment ( "@bors r+" ) . await ?;
556
+ assert_eq ! (
557
+ tester. get_comment( ) . await ?,
558
+ format!(
559
+ "Commit pr-{}-sha has been approved by `{}`" ,
560
+ default_pr_number( ) ,
561
+ User :: default_user( ) . name
562
+ ) ,
563
+ ) ;
564
+ check_pr_approved_by (
565
+ & tester,
566
+ default_pr_number ( ) . into ( ) ,
567
+ & User :: default_user ( ) . name ,
568
+ )
569
+ . await ;
570
+ Ok ( tester)
571
+ } )
572
+ . await ;
573
+ }
574
+
575
+ fn create_world_with_immediate_approve_config ( ) -> World {
576
+ let world = World :: default ( ) ;
577
+ world. default_repo ( ) . lock ( ) . set_config (
578
+ r#"
579
+ wait_on_ci_approval = false
580
+ [labels]
581
+ approve = ["+approved"]
582
+ "# ,
583
+ ) ;
584
+ world
585
+ }
586
+
587
+ fn create_world_with_ci_approved_config ( ) -> World {
510
588
let world = World :: default ( ) ;
511
589
world. default_repo ( ) . lock ( ) . set_config (
512
590
r#"
591
+ wait_on_ci_approval = true
513
592
[labels]
514
593
approve = ["+approved"]
515
594
"# ,
516
595
) ;
596
+ world. default_repo ( ) . lock ( ) . branches . push ( Branch :: new (
597
+ & format ! ( "pr-{}" , default_pr_number( ) ) ,
598
+ & format ! ( "pr-{}-sha" , default_pr_number( ) ) ,
599
+ ) ) ;
517
600
world
518
601
}
519
602
0 commit comments