@@ -19,6 +19,7 @@ use crate::github::{CommitSha, GithubUser, LabelTrigger, MergeError, PullRequest
19
19
use crate :: permissions:: PermissionType ;
20
20
use crate :: utils:: text:: suppress_github_mentions;
21
21
use anyhow:: { Context , anyhow} ;
22
+ use octocrab:: params:: checks:: CheckRunConclusion ;
22
23
use octocrab:: params:: checks:: CheckRunOutput ;
23
24
use octocrab:: params:: checks:: CheckRunStatus ;
24
25
use tracing:: log;
@@ -155,7 +156,7 @@ async fn cancel_previous_try_build(
155
156
) -> anyhow:: Result < Vec < String > > {
156
157
assert_eq ! ( build. status, BuildStatus :: Pending ) ;
157
158
158
- match cancel_build_workflows ( & repo. client , db, build) . await {
159
+ match cancel_build_workflows ( & repo. client , db, build, CheckRunConclusion :: Cancelled ) . await {
159
160
Ok ( workflow_ids) => {
160
161
tracing:: info!( "Try build cancelled" ) ;
161
162
Ok ( repo
@@ -267,7 +268,14 @@ pub(super) async fn command_try_cancel(
267
268
return Ok ( ( ) ) ;
268
269
} ;
269
270
270
- match cancel_build_workflows ( & repo. client , db. as_ref ( ) , build) . await {
271
+ match cancel_build_workflows (
272
+ & repo. client ,
273
+ db. as_ref ( ) ,
274
+ build,
275
+ CheckRunConclusion :: Cancelled ,
276
+ )
277
+ . await
278
+ {
271
279
Err ( error) => {
272
280
tracing:: error!(
273
281
"Could not cancel workflows for SHA {}: {error:?}" ,
@@ -298,6 +306,7 @@ pub async fn cancel_build_workflows(
298
306
client : & GithubRepositoryClient ,
299
307
db : & PgDbClient ,
300
308
build : & BuildModel ,
309
+ check_run_conclusion : CheckRunConclusion ,
301
310
) -> anyhow:: Result < Vec < RunId > > {
302
311
let pending_workflows = db. get_pending_workflows_for_build ( build) . await ?;
303
312
@@ -307,6 +316,20 @@ pub async fn cancel_build_workflows(
307
316
db. update_build_status ( build, BuildStatus :: Cancelled )
308
317
. await ?;
309
318
319
+ if let Some ( check_run_id) = build. check_run_id {
320
+ if let Err ( error) = client
321
+ . update_check_run (
322
+ check_run_id as u64 ,
323
+ CheckRunStatus :: Completed ,
324
+ Some ( check_run_conclusion) ,
325
+ None ,
326
+ )
327
+ . await
328
+ {
329
+ tracing:: error!( "Could not update check run {check_run_id}: {error:?}" ) ;
330
+ }
331
+ }
332
+
310
333
Ok ( pending_workflows)
311
334
}
312
335
@@ -967,4 +990,60 @@ try_failed = ["+foo", "+bar", "-baz"]
967
990
} )
968
991
. await ;
969
992
}
993
+
994
+ #[ sqlx:: test]
995
+ async fn try_cancel_updates_check_run_to_cancelled ( pool : sqlx:: PgPool ) {
996
+ run_test ( pool. clone ( ) , |mut tester| async {
997
+ tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
998
+ tester. post_comment ( "@bors try" ) . await ?;
999
+ tester. expect_comments ( 1 ) . await ;
1000
+
1001
+ tester. post_comment ( "@bors try cancel" ) . await ?;
1002
+ tester. expect_comments ( 1 ) . await ;
1003
+
1004
+ tester. expect_check_run (
1005
+ & tester. default_pr ( ) . await . get_gh_pr ( ) . head_sha ,
1006
+ TRY_BUILD_CHECK_RUN_NAME ,
1007
+ "Bors try build" ,
1008
+ CheckRunStatus :: Completed ,
1009
+ Some ( CheckRunConclusion :: Cancelled ) ,
1010
+ ) ;
1011
+
1012
+ Ok ( tester)
1013
+ } )
1014
+ . await ;
1015
+ }
1016
+
1017
+ #[ sqlx:: test]
1018
+ async fn new_try_build_cancels_previous_and_updates_check_run ( pool : sqlx:: PgPool ) {
1019
+ run_test ( pool. clone ( ) , |mut tester| async {
1020
+ tester. create_branch ( TRY_BRANCH_NAME ) . expect_suites ( 1 ) ;
1021
+ tester. post_comment ( "@bors try" ) . await ?;
1022
+ tester. expect_comments ( 1 ) . await ;
1023
+
1024
+ let prev_sha = tester. default_pr ( ) . await . get_gh_pr ( ) . head_sha ;
1025
+ tester
1026
+ . push_to_pr ( default_repo_name ( ) , default_pr_number ( ) )
1027
+ . await ?;
1028
+ tester. post_comment ( "@bors try" ) . await ?;
1029
+ tester. expect_comments ( 1 ) . await ;
1030
+
1031
+ tester. expect_check_run (
1032
+ & prev_sha,
1033
+ TRY_BUILD_CHECK_RUN_NAME ,
1034
+ "Bors try build" ,
1035
+ CheckRunStatus :: Completed ,
1036
+ Some ( CheckRunConclusion :: Cancelled ) ,
1037
+ ) ;
1038
+ tester. expect_check_run (
1039
+ & tester. default_pr ( ) . await . get_gh_pr ( ) . head_sha ,
1040
+ TRY_BUILD_CHECK_RUN_NAME ,
1041
+ "Bors try build" ,
1042
+ CheckRunStatus :: InProgress ,
1043
+ None ,
1044
+ ) ;
1045
+ Ok ( tester)
1046
+ } )
1047
+ . await ;
1048
+ }
970
1049
}
0 commit comments