Skip to content

Commit 56dd684

Browse files
committed
Remove get_build_kind function
As we now store this data in the database.
1 parent a278f96 commit 56dd684

File tree

3 files changed

+14
-27
lines changed

3 files changed

+14
-27
lines changed

src/bors/handlers/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ use crate::bors::handlers::review::{
2222
use crate::bors::handlers::trybuild::{command_try_build, command_try_cancel};
2323
use crate::bors::handlers::workflow::{handle_workflow_completed, handle_workflow_started};
2424
use crate::bors::merge_queue::MergeQueueSender;
25-
use crate::bors::{BorsContext, CommandPrefix, Comment, RepositoryState};
25+
use crate::bors::{
26+
AUTO_BRANCH_NAME, BorsContext, CommandPrefix, Comment, RepositoryState, TRY_BRANCH_NAME,
27+
};
2628
use crate::database::{DelegatedPermission, PullRequestModel};
2729
use crate::github::api::client::HideCommentReason;
2830
use crate::github::{GithubUser, LabelTrigger, PullRequest, PullRequestNumber};
@@ -674,6 +676,11 @@ async fn hide_try_build_started_comments(
674676
Ok(())
675677
}
676678

679+
/// Is this branch interesting for the bot?
680+
fn is_bors_observed_branch(branch: &str) -> bool {
681+
branch == TRY_BRANCH_NAME || branch == AUTO_BRANCH_NAME
682+
}
683+
677684
#[cfg(test)]
678685
mod tests {
679686
use crate::tests::{BorsTester, Comment, User, default_repo_name, run_test};

src/bors/handlers/workflow.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use crate::bors::comment::{
33
CommentTag, append_workflow_links_to_comment, build_failed_comment, try_build_succeeded_comment,
44
};
55
use crate::bors::event::{WorkflowRunCompleted, WorkflowRunStarted};
6-
use crate::bors::handlers::hide_try_build_started_comments;
76
use crate::bors::handlers::labels::handle_label_trigger;
7+
use crate::bors::handlers::{hide_try_build_started_comments, is_bors_observed_branch};
88
use crate::bors::merge_queue::MergeQueueSender;
9-
use crate::bors::{BuildKind, TRY_BRANCH_NAME, get_build_kind, is_bors_observed_branch};
9+
use crate::bors::{BuildKind, TRY_BRANCH_NAME};
1010
use crate::bors::{FailedWorkflowRun, RepositoryState, WorkflowRun};
1111
use crate::database::{
1212
BuildModel, BuildStatus, PullRequestModel, QueueStatus, WorkflowModel, WorkflowStatus,
@@ -167,10 +167,6 @@ async fn maybe_complete_build(
167167
merge_queue_tx: &MergeQueueSender,
168168
error_context: Option<String>,
169169
) -> anyhow::Result<()> {
170-
let Some(build_type) = get_build_kind(&payload.branch) else {
171-
return Ok(());
172-
};
173-
174170
let Some(build) = db
175171
.find_build(
176172
&payload.repository,
@@ -252,7 +248,7 @@ async fn maybe_complete_build(
252248
} else {
253249
BuildStatus::Failure
254250
};
255-
let trigger = match build_type {
251+
let trigger = match build.kind {
256252
BuildKind::Try => {
257253
if !build_succeeded {
258254
Some(LabelTrigger::TryBuildFailed)
@@ -289,7 +285,7 @@ async fn maybe_complete_build(
289285
}
290286

291287
// Trigger merge queue when an auto build completes
292-
if build_type == BuildKind::Auto {
288+
if build.kind == BuildKind::Auto {
293289
merge_queue_tx.notify().await?;
294290
}
295291

@@ -298,7 +294,7 @@ async fn maybe_complete_build(
298294
let comment_opt = if build_succeeded {
299295
tracing::info!("Build succeeded for PR {pr_num}");
300296

301-
if build_type == BuildKind::Try {
297+
if build.kind == BuildKind::Try {
302298
Some(try_build_succeeded_comment(
303299
&db_workflow_runs,
304300
payload.commit_sha,
@@ -338,7 +334,7 @@ async fn maybe_complete_build(
338334
))
339335
};
340336

341-
if build_type == BuildKind::Try {
337+
if build.kind == BuildKind::Try {
342338
hide_try_build_started_comments(repo, db, &pr).await?;
343339
}
344340

src/bors/mod.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,19 +239,3 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
239239
}
240240
message
241241
}
242-
243-
/// Is this branch interesting for the bot?
244-
pub fn is_bors_observed_branch(branch: &str) -> bool {
245-
branch == TRY_BRANCH_NAME || branch == AUTO_BRANCH_NAME
246-
}
247-
248-
/// Get the build type based on the branch where it happened.
249-
pub fn get_build_kind(branch: &str) -> Option<BuildKind> {
250-
if branch == TRY_BRANCH_NAME {
251-
Some(BuildKind::Try)
252-
} else if branch == AUTO_BRANCH_NAME {
253-
Some(BuildKind::Auto)
254-
} else {
255-
None
256-
}
257-
}

0 commit comments

Comments
 (0)