Skip to content

Commit 4ae0dc9

Browse files
committed
github: allow all jobs in a suite to be cancelled at once
1 parent f7683e1 commit 4ae0dc9

File tree

2 files changed

+57
-21
lines changed

2 files changed

+57
-21
lines changed

github/server/src/main.rs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,10 @@ async fn process_deliveries(app: &Arc<App>) -> Result<()> {
828828
}
829829
"check_run" if &payload.action == "requested_action" => {
830830
let actid = if let Some(ra) = &payload.requested_action {
831-
if ra.identifier != "auth" && ra.identifier != "cancel" {
831+
if ra.identifier != "auth"
832+
&& ra.identifier != "cancel"
833+
&& ra.identifier != "cancel_all"
834+
{
832835
/*
833836
* Authorisation and cancellation are the only actions
834837
* we know how to do for now.
@@ -904,23 +907,49 @@ async fn process_deliveries(app: &Arc<App>) -> Result<()> {
904907
continue;
905908
}
906909
CheckRunVariety::Basic => {
907-
if actid != "cancel" {
908-
warn!(
909-
log,
910-
"delivery {} for {:?} on basic check run",
911-
del.seq,
912-
actid,
913-
);
914-
app.db.delivery_ack(del.seq, ack)?;
915-
continue;
910+
match actid.as_str() {
911+
"cancel" => {
912+
/*
913+
* Cancel any work that has been queued but not
914+
* yet performed:
915+
*/
916+
variety::basic::cancel(app, &cs, &mut cr)
917+
.await?;
918+
}
919+
"cancel_all" => {
920+
/*
921+
* Cancel any work that has been queued but not
922+
* yet performed for all basic variety check
923+
* runs in this suite:
924+
*/
925+
for mut cr in
926+
app.db.list_check_runs_for_suite(&cs.id)?
927+
{
928+
if !cr.active
929+
|| !matches!(
930+
cr.variety,
931+
CheckRunVariety::Basic
932+
)
933+
{
934+
continue;
935+
}
936+
937+
variety::basic::cancel(app, &cs, &mut cr)
938+
.await?;
939+
}
940+
}
941+
other => {
942+
warn!(
943+
log,
944+
"delivery {} for {:?} on basic check run",
945+
del.seq,
946+
other,
947+
);
948+
app.db.delivery_ack(del.seq, ack)?;
949+
continue;
950+
}
916951
}
917952

918-
/*
919-
* Cancel any work that has been queued but not yet
920-
* performed:
921-
*/
922-
variety::basic::cancel(app, &cs, &mut cr).await?;
923-
924953
app.db.delivery_ack(del.seq, ack)?;
925954
continue;
926955
}

github/server/src/variety/basic.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,18 @@ pub(crate) async fn flush(
199199
summary += "\n\n";
200200
}
201201

202-
let cancel = vec![octorust::types::ChecksCreateRequestActions {
203-
description: "Cancel execution and fail the check.".into(),
204-
identifier: "cancel".into(),
205-
label: "Cancel".into(),
206-
}];
202+
let cancel = vec![
203+
octorust::types::ChecksCreateRequestActions {
204+
description: "Cancel execution and fail the check.".into(),
205+
identifier: "cancel".into(),
206+
label: "Cancel this job".into(),
207+
},
208+
octorust::types::ChecksCreateRequestActions {
209+
description: "Cancel all jobs and fail all checks.".into(),
210+
identifier: "cancel_all".into(),
211+
label: "Cancel all jobs".into(),
212+
},
213+
];
207214

208215
Ok(if p.complete {
209216
if let Some(e) = p.error.as_deref() {

0 commit comments

Comments
 (0)