@@ -119,7 +119,7 @@ pub(super) async fn handle_pull_request_opened(
119119 author : payload. pull_request . author . username . clone ( ) ,
120120 assignees,
121121 base_branch : payload. pull_request . base . name . clone ( ) ,
122- mergeable_state : MergeableState :: Unknown ,
122+ mergeable_state : payload . pull_request . mergeable_state . clone ( ) . into ( ) ,
123123 pr_status,
124124 } ,
125125 )
@@ -361,6 +361,7 @@ async fn notify_of_pushed_pr(
361361
362362#[ cfg( test) ]
363363mod tests {
364+ use insta:: assert_snapshot;
364365 use octocrab:: params:: checks:: { CheckRunConclusion , CheckRunStatus } ;
365366
366367 use crate :: bors:: PullRequestStatus ;
@@ -439,7 +440,7 @@ mod tests {
439440 tester. get_pr_copy ( ( ) ) . await . expect_unapproved ( ) ;
440441 Ok ( ( ) )
441442 } )
442- . await ;
443+ . await ;
443444 }
444445
445446 #[ sqlx:: test]
@@ -653,13 +654,13 @@ mod tests {
653654 run_test ( pool, async |tester : & mut BorsTester | {
654655 let pr = tester
655656 . open_pr ( default_repo_name ( ) , |pr| {
656- pr. mergeable_state = OctocrabMergeableState :: Unknown
657+ pr. mergeable_state = OctocrabMergeableState :: Unknown ;
657658 } )
658659 . await ?;
659- tester. push_to_branch ( default_branch_name ( ) ) . await ?;
660+ tester. push_to_branch ( default_branch_name ( ) , "sha" ) . await ?;
660661 tester
661662 . modify_pr_state ( pr. id ( ) , |pr| {
662- pr. mergeable_state = OctocrabMergeableState :: Dirty
663+ pr. mergeable_state = OctocrabMergeableState :: Dirty ;
663664 } )
664665 . await ;
665666 tester
@@ -672,6 +673,86 @@ mod tests {
672673 . await ;
673674 }
674675
676+ #[ sqlx:: test]
677+ async fn conflict_message_unknown_sha ( pool : sqlx:: PgPool ) {
678+ run_test ( pool, async |tester : & mut BorsTester | {
679+ let pr = tester
680+ . open_pr ( default_repo_name ( ) , |pr| {
681+ pr. mergeable_state = OctocrabMergeableState :: Clean ;
682+ } )
683+ . await ?;
684+ tester
685+ . modify_pr_state ( pr. id ( ) , |pr| {
686+ pr. mergeable_state = OctocrabMergeableState :: Dirty ;
687+ } )
688+ . await ;
689+ tester. push_to_branch ( default_branch_name ( ) , "sha" ) . await ?;
690+ assert_snapshot ! ( tester. get_next_comment_text( pr) . await ?, @":umbrella: The latest upstream changes made this pull request unmergeable. Please [resolve the merge conflicts](https://rustc-dev-guide.rust-lang.org/git.html#rebasing-and-conflicts)." ) ;
691+
692+ Ok ( ( ) )
693+ } )
694+ . await ;
695+ }
696+
697+ #[ sqlx:: test]
698+ async fn conflict_message_unknown_sha_approved ( pool : sqlx:: PgPool ) {
699+ run_test ( pool, async |tester : & mut BorsTester | {
700+ let pr = tester
701+ . open_pr ( default_repo_name ( ) , |pr| {
702+ pr. mergeable_state = OctocrabMergeableState :: Clean ;
703+ } )
704+ . await ?;
705+ tester. approve ( pr. id ( ) ) . await ?;
706+ tester
707+ . modify_pr_state ( pr. id ( ) , |pr| {
708+ pr. mergeable_state = OctocrabMergeableState :: Dirty ;
709+ } )
710+ . await ;
711+ tester. push_to_branch ( default_branch_name ( ) , "sha" ) . await ?;
712+ assert_snapshot ! ( tester. get_next_comment_text( pr. id( ) ) . await ?, @r"
713+ :umbrella: The latest upstream changes made this pull request unmergeable. Please [resolve the merge conflicts](https://rustc-dev-guide.rust-lang.org/git.html#rebasing-and-conflicts).
714+
715+ This pull request was unapproved.
716+ " ) ;
717+ tester. get_pr_copy ( pr. id ( ) ) . await . expect_unapproved ( ) ;
718+
719+ Ok ( ( ) )
720+ } )
721+ . await ;
722+ }
723+
724+ #[ sqlx:: test]
725+ async fn conflict_message_known_sha ( pool : sqlx:: PgPool ) {
726+ run_test ( pool, async |tester : & mut BorsTester | {
727+ let pr2 = tester
728+ . open_pr ( default_repo_name ( ) , |pr| {
729+ pr. mergeable_state = OctocrabMergeableState :: Clean ;
730+ } )
731+ . await ?;
732+
733+ let pr1 = tester
734+ . open_pr ( default_repo_name ( ) , |_| { } )
735+ . await ?;
736+ tester. approve ( pr1. id ( ) ) . await ?;
737+ tester. start_auto_build ( pr1. id ( ) ) . await ?;
738+ tester. workflow_full_success ( tester. auto_branch ( ) . await ) . await ?;
739+ tester. process_merge_queue ( ) . await ;
740+ tester. expect_comments ( pr1. id ( ) , 1 ) . await ;
741+ let sha = tester. auto_branch ( ) . await . get_sha ( ) . to_string ( ) ;
742+
743+ tester
744+ . modify_pr_state ( pr2. id ( ) , |pr| {
745+ pr. mergeable_state = OctocrabMergeableState :: Dirty ;
746+ } )
747+ . await ;
748+ tester. push_to_branch ( default_branch_name ( ) , & sha) . await ?;
749+ assert_snapshot ! ( tester. get_next_comment_text( pr2. id( ) ) . await ?, @":umbrella: The latest upstream changes (presumably #3) made this pull request unmergeable. Please [resolve the merge conflicts](https://rustc-dev-guide.rust-lang.org/git.html#rebasing-and-conflicts)." ) ;
750+
751+ Ok ( ( ) )
752+ } )
753+ . await ;
754+ }
755+
675756 #[ sqlx:: test]
676757 async fn enqueue_prs_on_pr_opened ( pool : sqlx:: PgPool ) {
677758 run_test ( pool, async |tester : & mut BorsTester | {
@@ -752,7 +833,7 @@ mod tests {
752833 " ) ;
753834 Ok ( ( ) )
754835 } )
755- . await ;
836+ . await ;
756837 gh. check_cancelled_workflows ( default_repo_name ( ) , & [ 123 ] ) ;
757838 }
758839
@@ -777,7 +858,7 @@ mod tests {
777858 " ) ;
778859 Ok ( ( ) )
779860 } )
780- . await ;
861+ . await ;
781862 }
782863
783864 #[ sqlx:: test]
0 commit comments