Skip to content

Commit 02899fb

Browse files
committed
Hide previous auto build started comments when an auto build finishes
1 parent c372f18 commit 02899fb

File tree

4 files changed

+35
-9
lines changed

4 files changed

+35
-9
lines changed

src/bors/handlers/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,15 @@ async fn unapprove_pr(
658658
handle_label_trigger(repo_state, pr.number, LabelTrigger::Unapproved).await
659659
}
660660

661-
/// Hide all previous "Try build started" comments on the given PR.
662-
async fn hide_try_build_started_comments(
661+
/// Hide all previous "Try/auto build started" comments on the given PR.
662+
async fn hide_build_started_comments(
663663
repo: &RepositoryState,
664664
db: &PgDbClient,
665665
pr: &PullRequestModel,
666+
tag: CommentTag,
666667
) -> anyhow::Result<()> {
667668
let outdated = db
668-
.get_tagged_bot_comments(repo.repository(), pr.number, CommentTag::TryBuildStarted)
669+
.get_tagged_bot_comments(repo.repository(), pr.number, tag)
669670
.await?;
670671
for comment in outdated {
671672
repo.client

src/bors/handlers/trybuild.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use super::{PullRequestData, deny_request};
4-
use super::{has_permission, hide_try_build_started_comments};
4+
use super::{has_permission, hide_build_started_comments};
55
use crate::PgDbClient;
66
use crate::bors::command::{CommandPrefix, Parent};
77
use crate::bors::comment::try_build_cancelled_comment;
@@ -73,7 +73,9 @@ pub(super) async fn command_try_build(
7373
let cancelled_workflow_urls = if let Some(build) = get_pending_build(pr.db) {
7474
let res = cancel_previous_try_build(repo, &db, build).await?;
7575
// Also try to hide previous "Try build started" comments that weren't hidden yet
76-
if let Err(error) = hide_try_build_started_comments(repo, &db, pr.db).await {
76+
if let Err(error) =
77+
hide_build_started_comments(repo, &db, pr.db, CommentTag::TryBuildStarted).await
78+
{
7779
tracing::error!("Failed to hide previous try build started comment(s): {error:?}");
7880
}
7981

src/bors/handlers/workflow.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::bors::comment::{
55
};
66
use crate::bors::event::{WorkflowRunCompleted, WorkflowRunStarted};
77
use crate::bors::handlers::labels::handle_label_trigger;
8-
use crate::bors::handlers::{hide_try_build_started_comments, is_bors_observed_branch};
8+
use crate::bors::handlers::{hide_build_started_comments, is_bors_observed_branch};
99
use crate::bors::merge_queue::MergeQueueSender;
1010
use crate::bors::{FailedWorkflowRun, RepositoryState, WorkflowRun};
1111
use crate::database::{
@@ -337,9 +337,11 @@ async fn maybe_complete_build(
337337
))
338338
};
339339

340-
if build.kind == BuildKind::Try {
341-
hide_try_build_started_comments(repo, db, &pr).await?;
342-
}
340+
let tag = match build.kind {
341+
BuildKind::Try => CommentTag::TryBuildStarted,
342+
BuildKind::Auto => CommentTag::AutoBuildStarted,
343+
};
344+
hide_build_started_comments(repo, db, &pr, tag).await?;
343345

344346
if let Some(comment) = comment_opt {
345347
repo.client.post_comment(pr_num, comment).await?;

src/bors/merge_queue.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ pub fn start_merge_queue(
491491
mod tests {
492492
use octocrab::params::checks::{CheckRunConclusion, CheckRunStatus};
493493

494+
use crate::github::api::client::HideCommentReason;
494495
use crate::tests::{BorsBuilder, GitHubState, run_test};
495496
use crate::{
496497
bors::{
@@ -1173,4 +1174,24 @@ auto_build_failed = ["+foo", "+bar", "-baz"]
11731174
})
11741175
.await;
11751176
}
1177+
1178+
#[sqlx::test]
1179+
async fn hide_auto_build_started_comment_after_workflow_finish(pool: sqlx::PgPool) {
1180+
run_test(pool, async |tester: &mut BorsTester| {
1181+
tester.approve(()).await?;
1182+
tester.process_merge_queue().await;
1183+
let comment = tester.get_next_comment(()).await?;
1184+
1185+
tester
1186+
.workflow_full_failure(tester.auto_branch().await)
1187+
.await?;
1188+
tester.expect_comments((), 1).await;
1189+
tester
1190+
.expect_hidden_comment(&comment, HideCommentReason::Outdated)
1191+
.await;
1192+
1193+
Ok(())
1194+
})
1195+
.await;
1196+
}
11761197
}

0 commit comments

Comments
 (0)