@@ -4,14 +4,13 @@ use crate::bors::event::{
4
4
PullRequestMerged , PullRequestOpened , PullRequestPushed , PullRequestReadyForReview ,
5
5
PullRequestReopened , PullRequestUnassigned , PushToBranch ,
6
6
} ;
7
- use crate :: bors:: handlers:: trybuild:: cancel_build_workflows;
8
7
use crate :: bors:: handlers:: unapprove_pr;
8
+ use crate :: bors:: handlers:: workflow:: { AutoBuildCancelReason , maybe_cancel_auto_build} ;
9
9
use crate :: bors:: mergeable_queue:: MergeableQueueSender ;
10
10
use crate :: bors:: { Comment , PullRequestStatus , RepositoryState } ;
11
- use crate :: database:: { BuildStatus , MergeableState } ;
11
+ use crate :: database:: MergeableState ;
12
12
use crate :: github:: { CommitSha , PullRequestNumber } ;
13
13
use crate :: utils:: text:: pluralize;
14
- use octocrab:: params:: checks:: CheckRunConclusion ;
15
14
use std:: sync:: Arc ;
16
15
17
16
pub ( super ) async fn handle_pull_request_edited (
@@ -55,44 +54,13 @@ pub(super) async fn handle_push_to_pull_request(
55
54
56
55
mergeable_queue. enqueue ( repo_state. repository ( ) . clone ( ) , pr_number) ;
57
56
58
- let mut auto_build_cancel_message: Option < String > = None ;
59
- if let Some ( auto_build) = & pr_model. auto_build {
60
- if auto_build. status == BuildStatus :: Pending {
61
- tracing:: info!( "Cancelling auto build for PR {pr_number} due to push" ) ;
62
-
63
- match cancel_build_workflows (
64
- & repo_state. client ,
65
- db. as_ref ( ) ,
66
- auto_build,
67
- CheckRunConclusion :: Cancelled ,
68
- )
69
- . await
70
- {
71
- Ok ( workflow_ids) => {
72
- tracing:: info!( "Auto build cancelled" ) ;
73
-
74
- let workflow_urls = repo_state
75
- . client
76
- . get_workflow_urls ( workflow_ids. into_iter ( ) ) ;
77
- auto_build_cancel_message = Some ( cancelled_workflows_message ( workflow_urls) ) ;
78
- }
79
- Err ( error) => {
80
- tracing:: error!(
81
- "Could not cancel workflows for SHA {}: {error:?}" ,
82
- auto_build. commit_sha
83
- ) ;
84
-
85
- auto_build_cancel_message = Some ( unclean_auto_build_cancelled_message ( ) ) ;
86
- }
87
- } ;
88
- }
89
-
90
- tracing:: info!(
91
- "Deleting auto build {} for PR {pr_number} due to push" ,
92
- auto_build. id
93
- ) ;
94
- db. delete_auto_build ( & pr_model) . await ?;
95
- }
57
+ let auto_build_cancel_message = maybe_cancel_auto_build (
58
+ & repo_state. client ,
59
+ & db,
60
+ & pr_model,
61
+ AutoBuildCancelReason :: PushToPR ,
62
+ )
63
+ . await ?;
96
64
97
65
if !pr_model. is_approved ( ) {
98
66
return Ok ( ( ) ) ;
@@ -314,21 +282,6 @@ PR will need to be re-approved."#,
314
282
. await
315
283
}
316
284
317
- fn cancelled_workflows_message ( workflow_urls : impl Iterator < Item = String > ) -> String {
318
- let mut comment =
319
- r#"Auto build cancelled due to push to branch. Cancelled workflows:"# . to_string ( ) ;
320
- for url in workflow_urls {
321
- comment += format ! ( "\n - {}" , url) . as_str ( ) ;
322
- }
323
-
324
- comment
325
- }
326
-
327
- fn unclean_auto_build_cancelled_message ( ) -> String {
328
- "Auto build was cancelled due to push to branch. It was not possible to cancel some workflows."
329
- . to_string ( )
330
- }
331
-
332
285
#[ cfg( test) ]
333
286
mod tests {
334
287
use octocrab:: params:: checks:: { CheckRunConclusion , CheckRunStatus } ;
@@ -758,32 +711,6 @@ mod tests {
758
711
. await ;
759
712
}
760
713
761
- #[ sqlx:: test]
762
- async fn delete_completed_auto_build_on_push ( pool : sqlx:: PgPool ) {
763
- BorsBuilder :: new ( pool)
764
- . github ( gh_state_with_merge_queue ( ) )
765
- . run_test ( async |tester| {
766
- tester. post_comment ( "@bors r+" ) . await ?;
767
- tester. expect_comments ( 1 ) . await ;
768
- tester. process_merge_queue ( ) . await ;
769
- tester. expect_comments ( 1 ) . await ;
770
- tester
771
- . wait_for_default_pr ( |pr| pr. auto_build . is_some ( ) )
772
- . await ?;
773
- tester. workflow_full_success ( tester. auto_branch ( ) ) . await ?;
774
- tester. expect_comments ( 1 ) . await ;
775
- tester
776
- . push_to_pr ( default_repo_name ( ) , default_pr_number ( ) )
777
- . await ?;
778
- tester. expect_comments ( 1 ) . await ;
779
- tester
780
- . wait_for_default_pr ( |pr| pr. auto_build . is_none ( ) )
781
- . await ?;
782
- Ok ( ( ) )
783
- } )
784
- . await ;
785
- }
786
-
787
714
#[ sqlx:: test]
788
715
async fn cancel_pending_auto_build_on_push_comment ( pool : sqlx:: PgPool ) {
789
716
BorsBuilder :: new ( pool)
@@ -804,7 +731,8 @@ mod tests {
804
731
:warning: A new commit `pr-1-commit-1` was pushed to the branch, the
805
732
PR will need to be re-approved.
806
733
807
- Auto build cancelled due to push to branch. Cancelled workflows:
734
+ Auto build cancelled due to push. Cancelled workflows:
735
+
808
736
- https://github.com/rust-lang/borstest/actions/runs/1
809
737
" ) ;
810
738
Ok ( ( ) )
@@ -834,7 +762,7 @@ mod tests {
834
762
:warning: A new commit `pr-1-commit-1` was pushed to the branch, the
835
763
PR will need to be re-approved.
836
764
837
- Auto build was cancelled due to push to branch . It was not possible to cancel some workflows.
765
+ Auto build cancelled due to push. It was not possible to cancel some workflows.
838
766
" ) ;
839
767
Ok ( ( ) )
840
768
} )
0 commit comments