Skip to content

Squash & Approve - #828

Open
medzernik wants to merge 6 commits into
rust-lang:mainfrom
medzernik:691/impl-bors-squash-r-plus
Open

Squash & Approve#828
medzernik wants to merge 6 commits into
rust-lang:mainfrom
medzernik:691/impl-bors-squash-r-plus

Conversation

@medzernik

@medzernik medzernik commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Added a Squash and Approve function. This should fix #691.

Please let me know anything I can do to improve the code if needed.

I would add that in
https://github.com/medzernik/bors/blob/ab07984372498f757ab06438e926a6a6c0424c2b/src/bors/handlers/squash.rs#L25-L27

I wanted to use some more differentiated error states, but with anyhow and the general practice of returning Ok(X) even if an error technically occurs, I just wrapped the sha in an Option<sha>

Mentored by: @Kobzol

@medzernik
medzernik force-pushed the 691/impl-bors-squash-r-plus branch from 7fbdf0b to ab07984 Compare August 23, 2026 09:43
@medzernik
medzernik marked this pull request as draft August 24, 2026 14:01
Added a new command that can squash and, if successful, approve a the latest resulting commit
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
Signed-off-by: David Manca <1900179+medzernik@users.noreply.github.com>
@medzernik
medzernik force-pushed the 691/impl-bors-squash-r-plus branch from ab07984 to d1b84ce Compare September 6, 2026 21:37
@medzernik

Copy link
Copy Markdown
Contributor Author

Thanks! I'll try to fix the remaining errors in tests and get it cleaned up today or tommorow.

Signed-off-by: medzernik <medzernik@medzernik.dev>
@medzernik
medzernik marked this pull request as ready for review September 9, 2026 17:32
Signed-off-by: medzernik <medzernik@medzernik.dev>

@Kobzol Kobzol left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Left some comments.

There is one race condition that we'll need to handle in handle_push_to_pull_request. If we push the squashed commit, GitHub will send us a webhook about the push, which will unapprove the PR in handle_push_to_pull_request. Of course that is not ideal if we just approved it after the squash :)

I will push some unrelated refactoring towards that.

View changes since this review

Comment thread src/bors/mod.rs
BorsCommand::Retry => {}
BorsCommand::Cancel => {}
BorsCommand::Squash { .. } => {}
BorsCommand::SquashAndApprove { .. } => {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command should be documented in the help message below.

Comment thread src/bors/handlers/mod.rs
let pr_db = db2
.get_pull_request(repo2.repository(), pr_github.number)
.await?
.expect("TODO");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this fails, we should return an Err from the callback, saying that the PR was not found in the DB.


#[sqlx::test(migrator = "crate::MIGRATOR")]
async fn squash_two_commits_and_approve(pool: sqlx::PgPool) {
let pool = Arc::new(pool);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some leftover?

pr.reset_to_single_commit(Commit::from_sha("sha1"));
pr.add_commits(vec![Commit::from_sha("sha2")]);
});
ctx.post_comment("@bors squash").await?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be using @bors r+ squash, which is what we want to test, right?

Comment thread src/bors/command/mod.rs
/// Squash message for the commit
commit_message: SquashCommitMessage,
},
SquashAndApprove {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to actually parse the command 😆 I was surprised why it was doing nothing in tests.. 😆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement @bors r+ squash

2 participants