Skip to content

Commit 8cab6b7

Browse files
authored
Merge pull request #525 from Kobzol/ignore-blocks
Implement homu-compatible ignore blocks
2 parents 04985d0 + 5c49bcf commit 8cab6b7

File tree

3 files changed

+90
-13
lines changed

3 files changed

+90
-13
lines changed

src/bors/merge_queue.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,4 +1251,47 @@ auto_build_failed = ["+foo", "+bar", "-baz"]
12511251
})
12521252
.await;
12531253
}
1254+
1255+
#[sqlx::test]
1256+
async fn commit_message_skip_ignore_block(pool: sqlx::PgPool) {
1257+
run_test(pool, async |ctx: &mut BorsTester| {
1258+
ctx.edit_pr((), |pr| {
1259+
pr.description = r"This is a very good PR.
1260+
1261+
<!-- homu-ignore:start -->
1262+
ignore this 1
1263+
<!-- homu-ignore:end -->
1264+
1265+
include this
1266+
1267+
<!-- homu-ignore:start -->
1268+
ignore this 2
1269+
<!-- homu-ignore:end -->
1270+
1271+
also include this pls"
1272+
.to_string();
1273+
})
1274+
.await?;
1275+
1276+
ctx.approve(()).await?;
1277+
ctx.start_and_finish_auto_build(()).await?;
1278+
1279+
insta::assert_snapshot!(ctx.auto_branch().get_commit().message(), @r"
1280+
Auto merge of #1 - pr-1, r=default-user
1281+
Title of PR 1
1282+
1283+
This is a very good PR.
1284+
1285+
1286+
1287+
include this
1288+
1289+
1290+
1291+
also include this pls
1292+
");
1293+
Ok(())
1294+
})
1295+
.await;
1296+
}
12541297
}

src/bors/mod.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
use crate::config::RepositoryConfig;
2+
use crate::github::GithubRepoName;
3+
use crate::github::api::client::GithubRepositoryClient;
4+
use crate::permissions::UserPermissions;
5+
#[cfg(test)]
6+
use crate::tests::TestSyncMarker;
17
use arc_swap::ArcSwap;
28
use chrono::{DateTime, Utc};
39
pub use command::CommandParser;
@@ -8,20 +14,14 @@ pub use handlers::{handle_bors_global_event, handle_bors_repository_event};
814
use itertools::Itertools;
915
use octocrab::models::RunId;
1016
use octocrab::models::workflows::Job;
17+
use regex::{Regex, RegexBuilder};
1118
use serde::Serialize;
1219
use std::collections::HashMap;
1320
use std::fmt;
1421
use std::str::FromStr;
15-
use std::sync::{Arc, RwLock};
22+
use std::sync::{Arc, LazyLock, RwLock};
1623
use std::time::Duration;
1724

18-
use crate::config::RepositoryConfig;
19-
use crate::github::GithubRepoName;
20-
use crate::github::api::client::GithubRepositoryClient;
21-
use crate::permissions::UserPermissions;
22-
#[cfg(test)]
23-
use crate::tests::TestSyncMarker;
24-
2525
mod build;
2626
mod build_queue;
2727
mod command;
@@ -258,16 +258,37 @@ impl FromStr for PullRequestStatus {
258258
}
259259
}
260260

261-
/// Prefix used to specify custom try jobs in PR descriptions.
262-
pub const CUSTOM_TRY_JOB_PREFIX: &str = "try-job:";
263-
264261
#[derive(Debug, Clone)]
265262
pub enum MergeType {
266263
Try { try_jobs: Vec<String> },
267264
Auto,
268265
}
269266

267+
/// HTML comment that marks the start of a bors ignore block.
268+
/// The block is called "homu" to maintain compatibility with the old bors implementation
269+
/// (called homu).
270+
const IGNORE_BLOCK_START: &str = "<!-- homu-ignore:start -->";
271+
/// HTML comment that marks the end of a bors ignore block.
272+
const IGNORE_BLOCK_END: &str = "<!-- homu-ignore:end -->";
273+
274+
/// Returns a string with the given content that will be ignored by bors on GitHub.
275+
pub fn make_text_ignored_by_bors(text: &str) -> String {
276+
format!("{IGNORE_BLOCK_START}\n{text}\n{IGNORE_BLOCK_END}")
277+
}
278+
270279
pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: MergeType) -> String {
280+
/// Prefix used to specify custom try jobs in PR descriptions.
281+
const CUSTOM_TRY_JOB_PREFIX: &str = "try-job:";
282+
283+
static IGNORE_REGEX: LazyLock<Regex> = LazyLock::new(|| {
284+
RegexBuilder::new(r"<!--\s*homu-ignore:start\s*-->.*?<!--\s*homu-ignore:end\s*-->")
285+
.multi_line(true)
286+
.case_insensitive(true)
287+
.dot_matches_new_line(true)
288+
.build()
289+
.unwrap()
290+
});
291+
271292
let pr_number = pr.number();
272293

273294
let reviewer = match &merge_type {
@@ -290,6 +311,7 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
290311
MergeType::Try { .. } => String::new(),
291312
MergeType::Auto => pr.github.message.clone(),
292313
};
314+
let pr_description = IGNORE_REGEX.replace_all(&pr_description, "");
293315

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

src/github/rollup.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{GithubRepoName, PullRequest, PullRequestNumber};
22
use crate::PgDbClient;
3+
use crate::bors::make_text_ignored_by_bors;
34
use crate::github::api::client::GithubRepositoryClient;
45
use crate::github::api::operations::{ForcePush, MergeError};
56
use crate::github::oauth::{OAuthClient, UserGitHubClient};
@@ -325,12 +326,13 @@ async fn create_rollup(
325326
body.push_str("\nr? @ghost");
326327

327328
let similar_rollup_link = format!(
328-
"{web_url}/queue/{repo_name}?prs={}",
329+
"[Create a similar rollup]({web_url}/queue/{repo_name}?prs={})",
329330
pr_nums.iter().copied().map(|s| s.to_string()).join(",")
330331
);
331332
writeln!(
332333
body,
333-
"\n\n[Create a similar rollup]({similar_rollup_link})\n"
334+
"\n\n{}\n",
335+
make_text_ignored_by_bors(&similar_rollup_link)
334336
)?;
335337

336338
let title = format!("Rollup of {} pull requests", successes.len());
@@ -472,7 +474,9 @@ mod tests {
472474
473475
r? @ghost
474476
477+
<!-- homu-ignore:start -->
475478
[Create a similar rollup](https://bors-test.com/queue/borstest?prs=2,3,4,5)
479+
<!-- homu-ignore:end -->
476480
");
477481
}
478482

@@ -510,7 +514,9 @@ mod tests {
510514
511515
r? @ghost
512516
517+
<!-- homu-ignore:start -->
513518
[Create a similar rollup](https://bors-test.com/queue/borstest?prs=2,3,4)
519+
<!-- homu-ignore:end -->
514520
");
515521
}
516522

@@ -542,7 +548,9 @@ mod tests {
542548
543549
r? @ghost
544550
551+
<!-- homu-ignore:start -->
545552
[Create a similar rollup](https://bors-test.com/queue/borstest?prs=2,3)
553+
<!-- homu-ignore:end -->
546554
");
547555
}
548556

@@ -580,7 +588,9 @@ mod tests {
580588
581589
r? @ghost
582590
591+
<!-- homu-ignore:start -->
583592
[Create a similar rollup](https://bors-test.com/queue/borstest?prs=2,3,4,5)
593+
<!-- homu-ignore:end -->
584594
");
585595
}
586596

@@ -607,7 +617,9 @@ mod tests {
607617
608618
r? @ghost
609619
620+
<!-- homu-ignore:start -->
610621
[Create a similar rollup](https://bors-test.com/queue/borstest?prs=3,2)
622+
<!-- homu-ignore:end -->
611623
");
612624
}
613625

0 commit comments

Comments
 (0)