@@ -19,6 +19,7 @@ use crate::github::{CommitSha, GithubUser, LabelTrigger, MergeError, PullRequest
1919use crate :: permissions:: PermissionType ;
2020use crate :: utils:: text:: suppress_github_mentions;
2121use anyhow:: { Context , anyhow} ;
22+ use octocrab:: params:: checks:: CheckRunConclusion ;
2223use octocrab:: params:: checks:: CheckRunOutput ;
2324use octocrab:: params:: checks:: CheckRunStatus ;
2425use tracing:: log;
@@ -155,7 +156,7 @@ async fn cancel_previous_try_build(
155156) -> anyhow:: Result < Vec < String > > {
156157 assert_eq ! ( build. status, BuildStatus :: Pending ) ;
157158
158- match cancel_build_workflows ( & repo. client , db, build) . await {
159+ match cancel_build_workflows ( & repo. client , db, build, CheckRunConclusion :: Cancelled ) . await {
159160 Ok ( workflow_ids) => {
160161 tracing:: info!( "Try build cancelled" ) ;
161162 Ok ( repo
@@ -267,7 +268,14 @@ pub(super) async fn command_try_cancel(
267268 return Ok ( ( ) ) ;
268269 } ;
269270
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+ {
271279 Err ( error) => {
272280 tracing:: error!(
273281 "Could not cancel workflows for SHA {}: {error:?}" ,
@@ -298,6 +306,7 @@ pub async fn cancel_build_workflows(
298306 client : & GithubRepositoryClient ,
299307 db : & PgDbClient ,
300308 build : & BuildModel ,
309+ check_run_conclusion : CheckRunConclusion ,
301310) -> anyhow:: Result < Vec < RunId > > {
302311 let pending_workflows = db. get_pending_workflows_for_build ( build) . await ?;
303312
@@ -307,6 +316,20 @@ pub async fn cancel_build_workflows(
307316 db. update_build_status ( build, BuildStatus :: Cancelled )
308317 . await ?;
309318
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+
310333 Ok ( pending_workflows)
311334}
312335
@@ -967,4 +990,60 @@ try_failed = ["+foo", "+bar", "-baz"]
967990 } )
968991 . await ;
969992 }
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+ }
9701049}
0 commit comments