Skip to content

Commit 282a307

Browse files
committed
Remove homu-ignore blocks also in rollup merge commit messages
1 parent c894332 commit 282a307

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed

src/bors/mod.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,8 @@ pub fn make_text_ignored_by_bors(text: &str) -> String {
287287
format!("{IGNORE_BLOCK_START}\n{text}\n{IGNORE_BLOCK_END}")
288288
}
289289

290-
pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: MergeType) -> String {
291-
/// Prefix used to specify custom try jobs in PR descriptions.
292-
const CUSTOM_TRY_JOB_PREFIX: &str = "try-job:";
293-
290+
/// Remove homu-ignore blocks from the merge message
291+
pub fn normalize_merge_message(message: &str) -> String {
294292
static IGNORE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
295293
RegexBuilder::new(r"<!--\s*homu-ignore:start\s*-->.*?<!--\s*homu-ignore:end\s*-->")
296294
.multi_line(true)
@@ -299,6 +297,12 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
299297
.build()
300298
.unwrap()
301299
});
300+
IGNORE_REGEX.replace_all(message, "").to_string()
301+
}
302+
303+
pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: MergeType) -> String {
304+
/// Prefix used to specify custom try jobs in PR descriptions.
305+
const CUSTOM_TRY_JOB_PREFIX: &str = "try-job:";
302306

303307
let pr_number = pr.number();
304308

@@ -322,7 +326,7 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
322326
MergeType::Try { .. } => String::new(),
323327
MergeType::Auto => pr.github.message.clone(),
324328
};
325-
let pr_description = IGNORE_REGEX.replace_all(&pr_description, "");
329+
let pr_description = normalize_merge_message(&pr_description);
326330

327331
let mut message = format!(
328332
r#"Auto merge of #{pr_number} - {pr_label}, r={reviewer}

src/github/rollup.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{GithubRepoName, PullRequest, PullRequestNumber};
22
use crate::PgDbClient;
3-
use crate::bors::make_text_ignored_by_bors;
3+
use crate::bors::{make_text_ignored_by_bors, normalize_merge_message};
44
use crate::github::api::client::GithubRepositoryClient;
55
use crate::github::api::operations::MergeError;
66
use crate::github::oauth::{OAuthClient, UserGitHubClient};
@@ -299,6 +299,7 @@ async fn create_rollup(
299299
pr.title,
300300
pr_github.message
301301
);
302+
let merge_msg = normalize_merge_message(&merge_msg);
302303

303304
// Merge the PR's head commit into the rollup branch
304305
let merge_attempt = user_client
@@ -665,6 +666,62 @@ mod tests {
665666
");
666667
}
667668

669+
#[sqlx::test]
670+
async fn rollup_remove_homu_ignore_block(pool: sqlx::PgPool) {
671+
let gh = run_test((pool, rollup_state()), async |ctx: &mut BorsTester| {
672+
let pr2 = ctx
673+
.open_pr(default_repo_name(), |pr| {
674+
pr.description = r"This is a very good PR.
675+
676+
<!-- homu-ignore:start -->
677+
ignore this 1
678+
<!-- homu-ignore:end -->
679+
680+
include this
681+
682+
<!-- homu-ignore:start -->
683+
ignore this 2
684+
<!-- homu-ignore:end -->
685+
686+
also include this pls"
687+
.to_string();
688+
})
689+
.await?;
690+
ctx.approve(pr2.id()).await?;
691+
692+
make_rollup(ctx, &[&pr2])
693+
.await?
694+
.assert_status(StatusCode::TEMPORARY_REDIRECT);
695+
Ok(())
696+
})
697+
.await;
698+
let rollup_branch = gh
699+
.get_repo(fork_repo())
700+
.lock()
701+
.branches()
702+
.iter()
703+
.find(|branch| branch.name().starts_with("rollup"))
704+
.unwrap()
705+
.clone();
706+
// Find the rollup merge commit
707+
let rollup_merge_commit = rollup_branch.get_commit_history().last().unwrap().clone();
708+
insta::assert_snapshot!(rollup_merge_commit.message(), @"
709+
Rollup merge of #2 - pr-2, r=default-user
710+
711+
Title of PR 2
712+
713+
This is a very good PR.
714+
715+
716+
717+
include this
718+
719+
720+
721+
also include this pls
722+
");
723+
}
724+
668725
async fn make_rollup(
669726
ctx: &mut BorsTester,
670727
prs: &[&PullRequest],

0 commit comments

Comments
 (0)