Skip to content

Commit 3a28737

Browse files
committed
Batch mergeability checks on base branch pushes
1 parent 052f670 commit 3a28737

12 files changed

Lines changed: 472 additions & 151 deletions

File tree

src/bors/build_queue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ async fn maybe_timeout_build(
213213
BuildKind::Auto => LabelTrigger::AutoBuildFailed,
214214
};
215215
let gh_pr = repo.client.get_pull_request(pr.number).await?;
216-
handle_label_trigger(repo, &gh_pr, trigger).await?;
216+
handle_label_trigger(repo, &gh_pr.into(), trigger).await?;
217217

218218
if let Err(error) = repo
219219
.client
@@ -348,7 +348,7 @@ async fn maybe_complete_build(
348348
.await?;
349349
if let Some(trigger) = trigger {
350350
let pr = repo.client.get_pull_request(pr_num).await?;
351-
handle_label_trigger(repo, &pr, trigger).await?;
351+
handle_label_trigger(repo, &pr.into(), trigger).await?;
352352
}
353353

354354
if let Some(check_run_id) = build.check_run_id {

src/bors/handlers/autobuild.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ pub(super) async fn command_retry(
3838
merge_queue_tx.notify().await?;
3939

4040
// Retrying is essentially like a reapproval
41-
handle_label_trigger(&repo_state, pr.github, LabelTrigger::Approved).await?;
41+
handle_label_trigger(
42+
&repo_state,
43+
&pr.github.clone().into(),
44+
LabelTrigger::Approved,
45+
)
46+
.await?;
4247
} else {
4348
let pending_auto_build = pr_model
4449
.auto_build

src/bors/handlers/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::bors::{
2828
TRY_BRANCH_NAME,
2929
};
3030
use crate::database::{DelegatedPermission, PullRequestModel};
31-
use crate::github::{CommitSha, GithubUser, LabelTrigger, PullRequest, PullRequestNumber};
31+
use crate::github::{CommitSha, GithubUser, LabelTrigger, PullRequest, PullRequestNumber, PullRequestSummary};
3232
use crate::permissions::PermissionType;
3333
use crate::{PgDbClient, TeamApiClient, load_repositories};
3434
use anyhow::Context;
@@ -751,7 +751,7 @@ pub async fn unapprove_pr(
751751
repo_state: &RepositoryState,
752752
db: &PgDbClient,
753753
pr_db: &PullRequestModel,
754-
pr_gh: &PullRequest,
754+
pr_gh: &PullRequestSummary,
755755
) -> anyhow::Result<()> {
756756
db.unapprove(pr_db).await?;
757757
handle_label_trigger(repo_state, pr_gh, LabelTrigger::Unapproved).await?;
@@ -817,7 +817,7 @@ pub async fn invalidate_pr(
817817
// Step 1: unapprove the pull request if it was approved
818818
// This happens everytime the PR is invalidated, if it was approved before
819819
let pr_unapproved = if pr_db.is_approved() {
820-
unapprove_pr(repo_state, db, pr_db, pr_gh).await?;
820+
unapprove_pr(repo_state, db, pr_db, &pr_gh.clone().into()).await?;
821821
true
822822
} else {
823823
false

src/bors/handlers/pr_events.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::bors::{AUTO_BRANCH_NAME, BorsContext, hide_tagged_comments};
1616
use crate::bors::{PullRequestStatus, RepositoryState};
1717
use crate::database::{PullRequestModel, UpsertPullRequestParams};
1818
use crate::github::CommitSha;
19-
use crate::utils::text::pluralize;
2019
use std::sync::Arc;
2120

2221
pub(super) async fn handle_pull_request_edited(
@@ -243,29 +242,22 @@ pub(super) async fn handle_push_to_branch(
243242
mergeability_queue: &MergeabilityQueueSender,
244243
payload: PushToBranch,
245244
) -> anyhow::Result<()> {
246-
let affected_prs = db
247-
.set_stale_mergeability_status_by_base_branch(repo_state.repository(), &payload.branch)
245+
db.set_stale_mergeability_status_by_base_branch(repo_state.repository(), &payload.branch)
248246
.await?;
249247

250-
if !affected_prs.is_empty() {
251-
tracing::info!(
252-
"Adding {} {} to the mergeability queue due to a new commit pushed to base branch `{}`",
253-
affected_prs.len(),
254-
pluralize("PR", affected_prs.len()),
255-
payload.branch
256-
);
248+
tracing::info!(
249+
"Adding a batch to the mergeability queue due to a new commit pushed to base branch `{}`",
250+
payload.branch
251+
);
257252

258-
// Try to find an auto build that matches this SHA
259-
let merged_pr = find_pr_by_merged_commit(&repo_state, &db, CommitSha(payload.sha))
260-
.await
261-
.ok()
262-
.flatten()
263-
.map(|pr| pr.number);
253+
// Try to find an auto build that matches this SHA
254+
let merged_pr = find_pr_by_merged_commit(&repo_state, &db, CommitSha(payload.sha))
255+
.await
256+
.ok()
257+
.flatten()
258+
.map(|pr| pr.number);
264259

265-
for pr in affected_prs {
266-
mergeability_queue.enqueue_pr(&pr, merged_pr);
267-
}
268-
}
260+
mergeability_queue.enqueue_batch(repo_state.repository(), &payload.branch, merged_pr);
269261

270262
Ok(())
271263
}

src/bors/handlers/review.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ pub(super) async fn command_approve(
133133
)
134134
.await?;
135135

136-
handle_label_trigger(&repo_state, pr.github, LabelTrigger::Approved).await
136+
handle_label_trigger(
137+
&repo_state,
138+
&pr.github.clone().into(),
139+
LabelTrigger::Approved,
140+
)
141+
.await
137142
}
138143

139144
/// Normalize approvers (given after @bors r=) by removing leading @, possibly from multiple

src/bors/labels.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::collections::HashSet;
33
use tracing::log;
44

55
use crate::bors::RepositoryState;
6-
use crate::github::{LabelModification, LabelTrigger, PullRequest};
6+
use crate::github::{LabelModification, LabelTrigger, PullRequestSummary};
77

88
/// If there are any label modifications that should be performed on the given PR when `trigger`
99
/// happens, this function will perform them.
1010
pub async fn handle_label_trigger(
1111
repo: &RepositoryState,
12-
pr: &PullRequest,
12+
pr: &PullRequestSummary,
1313
trigger: LabelTrigger,
1414
) -> anyhow::Result<()> {
1515
let mut add: Vec<String> = Vec::new();

src/bors/merge_queue.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ async fn handle_start_auto_build(
352352
update_pr_with_known_mergeability(
353353
repo,
354354
&ctx.db,
355-
&gh_pr,
355+
&gh_pr.into(),
356356
pr,
357357
mergeability_sender.get_conflict_source(pr),
358358
)
@@ -405,7 +405,7 @@ async fn handle_start_auto_build(
405405
update_pr_with_known_mergeability(
406406
repo,
407407
&ctx.db,
408-
&gh_pr,
408+
&gh_pr.into(),
409409
pr,
410410
mergeability_sender.get_conflict_source(pr),
411411
)
@@ -466,7 +466,7 @@ Actual head SHA: {actual_sha}"#,
466466

467467
// Note: we don't use invalidate_pr here, because we know that the PR is a rollup,
468468
// to have more control over the message.
469-
unapprove_pr(repo, &ctx.db, pr, &gh_pr).await?;
469+
unapprove_pr(repo, &ctx.db, pr, &gh_pr.clone().into()).await?;
470470

471471
mismatches.sort_by_key(|mismatch| mismatch.member);
472472

0 commit comments

Comments
 (0)