-
Notifications
You must be signed in to change notification settings - Fork 38
feat: Don't allow the merging of PRs when they don't have a clean state [WIP] #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,9 @@ use crate::bors::RepositoryState; | |
| use crate::bors::command::RollupMode; | ||
| use crate::bors::command::{Approver, CommandPrefix}; | ||
| use crate::bors::comment::{ | ||
| approve_blocking_labels_present, approve_non_open_pr_comment, approve_wip_title, | ||
| approved_comment, delegate_comment, delegate_try_builds_comment, unapprove_non_open_pr_comment, | ||
| approve_blocking_labels_present, approve_non_clean_pr, approve_non_open_pr_comment, | ||
| approve_wip_title, approved_comment, delegate_comment, delegate_try_builds_comment, | ||
| unapprove_non_open_pr_comment, | ||
| }; | ||
| use crate::bors::handlers::labels::handle_label_trigger; | ||
| use crate::bors::handlers::workflow::{AutoBuildCancelReason, maybe_cancel_auto_build}; | ||
|
|
@@ -20,6 +21,7 @@ use crate::github::LabelTrigger; | |
| use crate::github::{GithubUser, PullRequestNumber}; | ||
| use crate::permissions::PermissionType; | ||
| use crate::{BorsContext, PgDbClient}; | ||
| use octocrab::models::pulls::MergeableState; | ||
|
|
||
| /// Approve a pull request. | ||
| /// A pull request can only be approved by a user of sufficient authority. | ||
|
|
@@ -81,6 +83,10 @@ async fn check_pr_approval_validity( | |
| return Ok(Some(approve_non_open_pr_comment())); | ||
| } | ||
|
|
||
| if matches!(pr.github.mergeable_state, MergeableState::Dirty) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do indeed treat both |
||
| return Ok(Some(approve_non_clean_pr())); | ||
| } | ||
|
|
||
| // Check WIP title | ||
| let title = pr.github.title.to_lowercase(); | ||
| if let Some(wip_kw) = WIP_KEYWORDS.iter().find(|kw| title.contains(*kw)) { | ||
|
|
@@ -1214,6 +1220,20 @@ mod tests { | |
| .await; | ||
| } | ||
|
|
||
| #[sqlx::test] | ||
| async fn approve_dirty_pr(pool: sqlx::PgPool) { | ||
| run_test(pool, async |tester: &mut BorsTester| { | ||
| tester.edit_pr((), |pr| pr.dirty_pull_request()).await?; | ||
| tester.post_comment("@bors r+").await?; | ||
| insta::assert_snapshot!(tester.get_next_comment_text(()).await?, @r" | ||
| :clipboard: Looks like this PR is not ready to be merged, ignoring approval. | ||
| "); | ||
| tester.get_pr_copy(()).await.expect_unapproved(); | ||
| Ok(()) | ||
| }) | ||
| .await; | ||
| } | ||
|
|
||
| #[sqlx::test] | ||
| async fn approve_closed_pr(pool: sqlx::PgPool) { | ||
| run_test(pool, async |tester: &mut BorsTester| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -206,6 +206,10 @@ impl PullRequest { | |||||
| self.status = PullRequestStatus::Draft; | ||||||
| } | ||||||
|
|
||||||
| pub fn dirty_pull_request(&mut self) { | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| self.mergeable_state = MergeableState::Dirty; | ||||||
| } | ||||||
|
|
||||||
| pub fn add_comment_to_history(&mut self, comment: Comment) { | ||||||
| self.comment_history.push(comment); | ||||||
| } | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.