@@ -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
@@ -273,18 +274,20 @@ async fn notify_of_pending_approval(
273
274
274
275
#[ cfg( test) ]
275
276
mod tests {
277
+ use tracing_test:: traced_test;
278
+
276
279
use crate :: {
277
280
github:: PullRequestNumber ,
278
281
tests:: mocks:: {
279
- default_pr_number, default_repo_name, run_test, BorsBuilder , BorsTester , Permissions ,
280
- PullRequestChangeEvent , User , World ,
282
+ default_pr_number, default_repo_name, run_test, BorsBuilder , BorsTester , Branch ,
283
+ Permissions , PullRequestChangeEvent , User , World ,
281
284
} ,
282
285
} ;
283
286
284
287
#[ sqlx:: test]
285
288
async fn default_approve ( pool : sqlx:: PgPool ) {
286
289
BorsBuilder :: new ( pool)
287
- . world ( create_world_with_approve_config ( ) )
290
+ . world ( create_world_with_immediate_approve_config ( ) )
288
291
. run_test ( |mut tester| async {
289
292
tester. post_comment ( "@bors r+" ) . await ?;
290
293
assert_eq ! (
@@ -310,7 +313,7 @@ mod tests {
310
313
#[ sqlx:: test]
311
314
async fn approve_on_behalf ( pool : sqlx:: PgPool ) {
312
315
BorsBuilder :: new ( pool)
313
- . world ( create_world_with_approve_config ( ) )
316
+ . world ( create_world_with_immediate_approve_config ( ) )
314
317
. run_test ( |mut tester| async {
315
318
let approve_user = "user1" ;
316
319
tester
@@ -351,7 +354,7 @@ mod tests {
351
354
#[ sqlx:: test]
352
355
async fn unapprove ( pool : sqlx:: PgPool ) {
353
356
BorsBuilder :: new ( pool)
354
- . world ( create_world_with_approve_config ( ) )
357
+ . world ( create_world_with_immediate_approve_config ( ) )
355
358
. run_test ( |mut tester| async {
356
359
tester. post_comment ( "@bors r+" ) . await ?;
357
360
assert_eq ! (
@@ -382,7 +385,7 @@ mod tests {
382
385
#[ sqlx:: test]
383
386
async fn unapprove_on_base_edited ( pool : sqlx:: PgPool ) {
384
387
BorsBuilder :: new ( pool)
385
- . world ( create_world_with_approve_config ( ) )
388
+ . world ( create_world_with_immediate_approve_config ( ) )
386
389
. run_test ( |mut tester| async {
387
390
tester. post_comment ( "@bors r+" ) . await ?;
388
391
assert_eq ! (
@@ -416,7 +419,7 @@ PR will need to be re-approved."#,
416
419
#[ sqlx:: test]
417
420
async fn edit_pr_do_nothing_when_base_not_edited ( pool : sqlx:: PgPool ) {
418
421
BorsBuilder :: new ( pool)
419
- . world ( create_world_with_approve_config ( ) )
422
+ . world ( create_world_with_immediate_approve_config ( ) )
420
423
. run_test ( |mut tester| async {
421
424
tester. post_comment ( "@bors r+" ) . await ?;
422
425
assert_eq ! (
@@ -468,7 +471,7 @@ PR will need to be re-approved."#,
468
471
#[ sqlx:: test]
469
472
async fn unapprove_on_push ( pool : sqlx:: PgPool ) {
470
473
BorsBuilder :: new ( pool)
471
- . world ( create_world_with_approve_config ( ) )
474
+ . world ( create_world_with_immediate_approve_config ( ) )
472
475
. run_test ( |mut tester| async {
473
476
tester. post_comment ( "@bors r+" ) . await ?;
474
477
assert_eq ! (
@@ -506,14 +509,47 @@ PR will need to be re-approved."#,
506
509
. await ;
507
510
}
508
511
509
- fn create_world_with_approve_config ( ) -> World {
512
+ #[ traced_test]
513
+ #[ sqlx:: test]
514
+ async fn approve_wait_for_ci ( pool : sqlx:: PgPool ) {
515
+ BorsBuilder :: new ( pool)
516
+ . world ( create_world_with_ci_approved_config ( ) )
517
+ . run_test ( |mut tester| async {
518
+ tester. post_comment ( "@bors r+" ) . await ?;
519
+ assert_eq ! (
520
+ tester. get_comment( ) . await ?,
521
+ ":hourglass_flowing_sand: Waiting for CI checks to complete before approving..."
522
+ ) ;
523
+ Ok ( tester)
524
+ } )
525
+ . await ;
526
+ }
527
+
528
+ fn create_world_with_immediate_approve_config ( ) -> World {
529
+ let world = World :: default ( ) ;
530
+ world. default_repo ( ) . lock ( ) . set_config (
531
+ r#"
532
+ wait_on_ci_approval = false
533
+ [labels]
534
+ approve = ["+approved"]
535
+ "# ,
536
+ ) ;
537
+ world
538
+ }
539
+
540
+ fn create_world_with_ci_approved_config ( ) -> World {
510
541
let world = World :: default ( ) ;
511
542
world. default_repo ( ) . lock ( ) . set_config (
512
543
r#"
544
+ wait_on_ci_approval = true
513
545
[labels]
514
546
approve = ["+approved"]
515
547
"# ,
516
548
) ;
549
+ world. default_repo ( ) . lock ( ) . branches . push ( Branch :: new (
550
+ & format ! ( "pr-{}" , default_pr_number( ) ) ,
551
+ & format ! ( "pr-{}-sha" , default_pr_number( ) ) ,
552
+ ) ) ;
517
553
world
518
554
}
519
555
0 commit comments