Skip to content

Commit e92b8d2

Browse files
authored
Merge pull request #433 from Kobzol/fix-tree-state-finish-bug
Correctly finish successful auto builds when the tree is closed
2 parents dec28af + 9377c73 commit e92b8d2

File tree

4 files changed

+72
-10
lines changed

4 files changed

+72
-10
lines changed

.sqlx/query-b1fe02180d44f3cdc04ca0be76163606a84a5ed390079e4786e471b2e8850e49.json renamed to .sqlx/query-92d160378de8ed75192f25e393d1eceee06cd95b22cc6efe813e5d1c9812ee14.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/development.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,17 @@ Make sure to also run `cargo sqlx migrate run` to apply the migrations to the da
137137
The goal is to check that we have a test database with production-like data, so that we can test that applying migrations will not produce errors on a non-empty database.
138138
- If it doesn't make sense to add any data to the migration (e.g. if the migration only adds an index), put `-- Empty to satisfy migration tests` into the file.
139139

140-
### Generate `.sqlx` directory
140+
### Regenerate `.sqlx` directory
141141
```console
142+
$ rm -rf .sqlx
142143
$ cargo sqlx prepare -- --all-targets
144+
$ git add .sqlx
143145
```
144146

145147
After that, you should commit the changes to the `.sqlx` directory.
146148

149+
Make sure to remove the `.sqlx` directory before running the `prepare` command, to ensure that leftover queries are not do not remain committed to the repository.
150+
147151
## Updating commands
148152
When modifying commands, make sure to update both:
149153

src/bors/merge_queue.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,4 +1045,59 @@ auto_build_failed = ["+foo", "+bar", "-baz"]
10451045
})
10461046
.await;
10471047
}
1048+
1049+
#[sqlx::test]
1050+
async fn finish_auto_build_while_tree_is_closed_1(pool: sqlx::PgPool) {
1051+
run_test(pool, async |tester: &mut BorsTester| {
1052+
// Start an auto build with the default priority (0)
1053+
tester.approve(()).await?;
1054+
tester.start_auto_build(()).await?;
1055+
1056+
// Now close the tree for priority below 100
1057+
tester.post_comment("@bors treeclosed=100").await?;
1058+
tester.expect_comments((), 1).await;
1059+
1060+
// Then finish the auto build AFTER the tree has been closed and then
1061+
// run the merge queue
1062+
tester.finish_auto_build(()).await?;
1063+
1064+
// And ensure that the PR was indeed merged
1065+
tester
1066+
.get_pr_copy(())
1067+
.await
1068+
.expect_status(PullRequestStatus::Merged)
1069+
.expect_auto_build(|b| b.status == BuildStatus::Success);
1070+
Ok(())
1071+
})
1072+
.await;
1073+
}
1074+
1075+
#[sqlx::test]
1076+
async fn finish_auto_build_while_tree_is_closed_2(pool: sqlx::PgPool) {
1077+
run_test(pool, async |tester: &mut BorsTester| {
1078+
// Start an auto build with the default priority (0)
1079+
tester.approve(()).await?;
1080+
tester.start_auto_build(()).await?;
1081+
1082+
// Finish the auto build BEFORE the tree has been closed, then close the tree,
1083+
// and only then run the merge queue
1084+
tester
1085+
.workflow_full_success(tester.auto_branch().await)
1086+
.await?;
1087+
1088+
tester.post_comment("@bors treeclosed=100").await?;
1089+
tester.expect_comments((), 1).await;
1090+
tester.process_merge_queue().await;
1091+
tester.expect_comments((), 1).await;
1092+
1093+
// And ensure that the PR was indeed merged
1094+
tester
1095+
.get_pr_copy(())
1096+
.await
1097+
.expect_status(PullRequestStatus::Merged)
1098+
.expect_auto_build(|b| b.status == BuildStatus::Success);
1099+
Ok(())
1100+
})
1101+
.await;
1102+
}
10481103
}

src/database/operations.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ pub(crate) async fn update_build_check_run_id(
970970
/// Fetches pull requests eligible for merge:
971971
/// - Only approved PRs that are open and mergeable
972972
/// - Includes only PRs with pending or successful auto builds
973-
/// - Excludes PRs that do not meet the tree closure priority threshold (if tree closed)
973+
/// - Excludes non-pending PRs that do not meet the tree closure priority threshold (if tree closed)
974974
pub(crate) async fn get_merge_queue_prs(
975975
executor: impl PgExecutor<'_>,
976976
repo: &GithubRepoName,
@@ -1007,10 +1007,13 @@ pub(crate) async fn get_merge_queue_prs(
10071007
AND pr.status = 'open'
10081008
AND pr.approved_by IS NOT NULL
10091009
AND pr.mergeable_state = 'mergeable'
1010-
-- Include only PRs with pending or successful auto builds
1011-
AND (auto_build.status IS NULL OR auto_build.status IN ('pending', 'success'))
1012-
-- Tree closure check (if tree_priority is set)
1013-
AND ($2::int IS NULL OR pr.priority >= $2)
1010+
AND
1011+
-- We ALWAYS need to return pending and successful PRs, regardless of tree state
1012+
auto_build.status IN ('pending', 'success') OR (
1013+
-- For PRs without a build status, we check if they pass the tree state
1014+
-- priority check, if the tree is closed
1015+
auto_build.status IS NULL AND ($2::int IS NULL OR pr.priority >= $2)
1016+
)
10141017
"#,
10151018
repo as &GithubRepoName,
10161019
tree_priority

0 commit comments

Comments
 (0)