Skip to content

Commit 27e3a1c

Browse files
Sakib25800Kobzol
authored andcommitted
Update check run on cancel_timed_out_builds
1 parent 4fb94ab commit 27e3a1c

File tree

3 files changed

+47
-17
lines changed

3 files changed

+47
-17
lines changed

src/bors/handlers/refresh.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::time::Duration;
33

44
use anyhow::Context;
55
use chrono::{DateTime, Utc};
6+
use octocrab::params::checks::{CheckRunConclusion, CheckRunStatus};
67
use std::collections::BTreeMap;
78

89
use crate::bors::Comment;
@@ -28,6 +29,22 @@ pub async fn cancel_timed_out_builds(
2829

2930
db.update_build_status(&build, BuildStatus::Cancelled)
3031
.await?;
32+
33+
if let Some(check_run_id) = build.check_run_id {
34+
if let Err(error) = repo
35+
.client
36+
.update_check_run(
37+
check_run_id as u64,
38+
CheckRunStatus::Completed,
39+
Some(CheckRunConclusion::TimedOut),
40+
None,
41+
)
42+
.await
43+
{
44+
tracing::error!("Could not update check run {check_run_id}: {error:?}");
45+
}
46+
}
47+
3148
if let Some(pr) = db.find_pr_by_build(&build).await? {
3249
if let Err(error) = cancel_build_workflows(&repo.client, db, &build).await {
3350
tracing::error!(
@@ -181,11 +198,13 @@ fn elapsed_time(date: DateTime<Utc>) -> Duration {
181198
mod tests {
182199
use crate::bors::PullRequestStatus;
183200
use crate::bors::handlers::refresh::MOCK_TIME;
201+
use crate::bors::handlers::trybuild::TRY_BUILD_CHECK_RUN_NAME;
184202
use crate::database::{MergeableState, OctocrabMergeableState};
185203
use crate::tests::mocks::{
186204
BorsBuilder, GitHubState, default_pr_number, default_repo_name, run_test,
187205
};
188206
use chrono::Utc;
207+
use octocrab::params::checks::{CheckRunConclusion, CheckRunStatus};
189208
use std::future::Future;
190209
use std::time::Duration;
191210
use tokio::runtime::RuntimeFlavor;
@@ -267,6 +286,33 @@ timeout = 3600
267286
.await;
268287
}
269288

289+
#[sqlx::test]
290+
async fn refresh_cancel_build_updates_check_run(pool: sqlx::PgPool) {
291+
BorsBuilder::new(pool)
292+
.github(gh_state_with_long_timeout())
293+
.run_test(|mut tester| async move {
294+
tester.post_comment("@bors try").await?;
295+
tester.expect_comments(1).await;
296+
297+
with_mocked_time(Duration::from_secs(4000), async {
298+
tester.cancel_timed_out_builds().await;
299+
})
300+
.await;
301+
tester.expect_comments(1).await;
302+
303+
tester.expect_check_run(
304+
&tester.default_pr().await.get_gh_pr().head_sha,
305+
TRY_BUILD_CHECK_RUN_NAME,
306+
"Bors try build",
307+
CheckRunStatus::Completed,
308+
Some(CheckRunConclusion::TimedOut),
309+
);
310+
311+
Ok(tester)
312+
})
313+
.await;
314+
}
315+
270316
#[sqlx::test]
271317
async fn refresh_cancel_workflow_after_timeout(pool: sqlx::PgPool) {
272318
let gh = BorsBuilder::new(pool)

src/bors/handlers/trybuild.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(super) const TRY_MERGE_BRANCH_NAME: &str = "automation/bors/try-merge";
3636
pub(super) const TRY_BRANCH_NAME: &str = "automation/bors/try";
3737

3838
// The name of the check run seen in the GitHub UI.
39-
const TRY_BUILD_CHECK_RUN_NAME: &str = "Bors try build";
39+
pub(super) const TRY_BUILD_CHECK_RUN_NAME: &str = "Bors try build";
4040

4141
/// Performs a so-called try build - merges the PR branch into a special branch designed
4242
/// for running CI checks.
@@ -910,10 +910,6 @@ try_failed = ["+foo", "+bar", "-baz"]
910910
None,
911911
);
912912

913-
let check_run = tester.get_check_run().await?;
914-
insta::assert_snapshot!(check_run.summary, @"");
915-
insta::assert_snapshot!(check_run.text, @"");
916-
917913
Ok(tester)
918914
})
919915
.await;

src/tests/mocks/bors.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use crate::github::api::load_repositories;
2626
use crate::github::server::BorsProcess;
2727
use crate::github::{GithubRepoName, PullRequestNumber};
2828
use crate::tests::mocks::comment::{Comment, GitHubIssueCommentEventPayload};
29-
use crate::tests::mocks::repository;
3029
use crate::tests::mocks::workflow::{
3130
CheckSuite, GitHubCheckRunEventPayload, GitHubCheckSuiteEventPayload,
3231
GitHubWorkflowEventPayload, TestWorkflowStatus, Workflow, WorkflowEvent, WorkflowEventKind,
@@ -274,17 +273,6 @@ impl BorsTester {
274273
self.get_branch("automation/bors/try")
275274
}
276275

277-
/// Get the latest check run.
278-
pub async fn get_check_run(&mut self) -> anyhow::Result<repository::CheckRunData> {
279-
Ok(self
280-
.default_repo()
281-
.lock()
282-
.check_runs
283-
.last()
284-
.unwrap()
285-
.clone())
286-
}
287-
288276
/// Wait until the next bot comment is received on the default repo and the default PR.
289277
pub async fn get_comment(&mut self) -> anyhow::Result<String> {
290278
Ok(self

0 commit comments

Comments
 (0)