@@ -37,6 +37,7 @@ pub(super) async fn command_approve(
3737 } ;
3838
3939 if repo_state. config . load ( ) . wait_on_ci_approval {
40+ tracing:: debug!( "Checking CI status for PR {}" , pr. number) ;
4041 // Get all the check suites for the PR.
4142 let checks = repo_state
4243 . client
@@ -276,15 +277,15 @@ mod tests {
276277 use crate :: {
277278 github:: PullRequestNumber ,
278279 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 ,
281282 } ,
282283 } ;
283284
284285 #[ sqlx:: test]
285286 async fn default_approve ( pool : sqlx:: PgPool ) {
286287 BorsBuilder :: new ( pool)
287- . world ( create_world_with_approve_config ( ) )
288+ . world ( create_world_with_immediate_approve_config ( ) )
288289 . run_test ( |mut tester| async {
289290 tester. post_comment ( "@bors r+" ) . await ?;
290291 assert_eq ! (
@@ -310,7 +311,7 @@ mod tests {
310311 #[ sqlx:: test]
311312 async fn approve_on_behalf ( pool : sqlx:: PgPool ) {
312313 BorsBuilder :: new ( pool)
313- . world ( create_world_with_approve_config ( ) )
314+ . world ( create_world_with_immediate_approve_config ( ) )
314315 . run_test ( |mut tester| async {
315316 let approve_user = "user1" ;
316317 tester
@@ -351,7 +352,7 @@ mod tests {
351352 #[ sqlx:: test]
352353 async fn unapprove ( pool : sqlx:: PgPool ) {
353354 BorsBuilder :: new ( pool)
354- . world ( create_world_with_approve_config ( ) )
355+ . world ( create_world_with_immediate_approve_config ( ) )
355356 . run_test ( |mut tester| async {
356357 tester. post_comment ( "@bors r+" ) . await ?;
357358 assert_eq ! (
@@ -382,7 +383,7 @@ mod tests {
382383 #[ sqlx:: test]
383384 async fn unapprove_on_base_edited ( pool : sqlx:: PgPool ) {
384385 BorsBuilder :: new ( pool)
385- . world ( create_world_with_approve_config ( ) )
386+ . world ( create_world_with_immediate_approve_config ( ) )
386387 . run_test ( |mut tester| async {
387388 tester. post_comment ( "@bors r+" ) . await ?;
388389 assert_eq ! (
@@ -416,7 +417,7 @@ PR will need to be re-approved."#,
416417 #[ sqlx:: test]
417418 async fn edit_pr_do_nothing_when_base_not_edited ( pool : sqlx:: PgPool ) {
418419 BorsBuilder :: new ( pool)
419- . world ( create_world_with_approve_config ( ) )
420+ . world ( create_world_with_immediate_approve_config ( ) )
420421 . run_test ( |mut tester| async {
421422 tester. post_comment ( "@bors r+" ) . await ?;
422423 assert_eq ! (
@@ -468,7 +469,7 @@ PR will need to be re-approved."#,
468469 #[ sqlx:: test]
469470 async fn unapprove_on_push ( pool : sqlx:: PgPool ) {
470471 BorsBuilder :: new ( pool)
471- . world ( create_world_with_approve_config ( ) )
472+ . world ( create_world_with_immediate_approve_config ( ) )
472473 . run_test ( |mut tester| async {
473474 tester. post_comment ( "@bors r+" ) . await ?;
474475 assert_eq ! (
@@ -506,14 +507,96 @@ PR will need to be re-approved."#,
506507 . await ;
507508 }
508509
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 {
510588 let world = World :: default ( ) ;
511589 world. default_repo ( ) . lock ( ) . set_config (
512590 r#"
591+ wait_on_ci_approval = true
513592[labels]
514593approve = ["+approved"]
515594"# ,
516595 ) ;
596+ world. default_repo ( ) . lock ( ) . branches . push ( Branch :: new (
597+ & format ! ( "pr-{}" , default_pr_number( ) ) ,
598+ & format ! ( "pr-{}-sha" , default_pr_number( ) ) ,
599+ ) ) ;
517600 world
518601 }
519602
0 commit comments