Skip to content

Commit 9dd3c49

Browse files
committed
Add to mergeable queue on PR edit base change
1 parent 1da0226 commit 9dd3c49

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

src/bors/handlers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ pub async fn handle_bors_repository_event(
132132
let span =
133133
tracing::info_span!("Pull request edited", repo = payload.repository.to_string());
134134

135-
handle_pull_request_edited(repo, db, payload)
135+
handle_pull_request_edited(repo, db, mergeable_queue, payload)
136136
.instrument(span.clone())
137137
.await?;
138138
}

src/bors/handlers/pr_events.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::Arc;
1414
pub(super) async fn handle_pull_request_edited(
1515
repo_state: Arc<RepositoryState>,
1616
db: Arc<PgDbClient>,
17+
mergeable_queue: Arc<MergeableQueue>,
1718
payload: PullRequestEdited,
1819
) -> anyhow::Result<()> {
1920
let pr = &payload.pull_request;
@@ -33,6 +34,10 @@ pub(super) async fn handle_pull_request_edited(
3334
return Ok(());
3435
};
3536

37+
mergeable_queue
38+
.enqueue(repo_state.repository().clone(), pr_number)
39+
.await;
40+
3641
if !pr_model.is_approved() {
3742
return Ok(());
3843
}
@@ -214,6 +219,7 @@ mod tests {
214219
database::MergeableState,
215220
tests::mocks::{User, default_branch_name, default_repo_name, run_test},
216221
};
222+
use octocrab::models::pulls::MergeableState as OctocrabMergeableState;
217223

218224
#[sqlx::test]
219225
async fn unapprove_on_base_edited(pool: sqlx::PgPool) {
@@ -348,7 +354,7 @@ mod tests {
348354
run_test(pool.clone(), |mut tester| async {
349355
tester
350356
.edit_pr(default_repo_name(), default_pr_number(), |pr| {
351-
pr.mergeable_state = octocrab::models::pulls::MergeableState::Dirty;
357+
pr.mergeable_state = OctocrabMergeableState::Dirty;
352358
})
353359
.await?;
354360
tester
@@ -448,4 +454,33 @@ mod tests {
448454
})
449455
.await;
450456
}
457+
458+
#[sqlx::test]
459+
async fn mergeable_queue_processes_pr_base_change(pool: sqlx::PgPool) {
460+
run_test(pool, |mut tester| async {
461+
tester
462+
.edit_pr(default_repo_name(), default_pr_number(), |pr| {
463+
pr.mergeable_state = OctocrabMergeableState::Clean;
464+
})
465+
.await?;
466+
tester
467+
.wait_for_default_pr(|pr| pr.mergeable_state == MergeableState::Mergeable)
468+
.await?;
469+
470+
let branch = tester.create_branch("beta").clone();
471+
tester
472+
.edit_pr(default_repo_name(), default_pr_number(), |pr| {
473+
pr.base_branch = branch;
474+
pr.mergeable_state = OctocrabMergeableState::Unknown;
475+
})
476+
.await?;
477+
tester
478+
.wait_for_default_pr(|pr| {
479+
pr.base_branch == "beta" && pr.mergeable_state == MergeableState::Unknown
480+
})
481+
.await?;
482+
Ok(tester)
483+
})
484+
.await;
485+
}
451486
}

src/bors/mergeable_queue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl MergeableQueue {
2121
Self { tx: Some(tx) }
2222
}
2323

24-
pub async fn push(&self, repository: GithubRepoName, pr_number: PullRequestNumber) {
24+
pub async fn enqueue(&self, repository: GithubRepoName, pr_number: PullRequestNumber) {
2525
if let Some(tx) = &self.tx {
2626
let item = MergeableQueueItem {
2727
repository,

0 commit comments

Comments
 (0)