diff --git a/src/bors/mod.rs b/src/bors/mod.rs index d46da393..c1caf39d 100644 --- a/src/bors/mod.rs +++ b/src/bors/mod.rs @@ -18,7 +18,6 @@ use crate::github::api::client::GithubRepositoryClient; use crate::permissions::UserPermissions; #[cfg(test)] use crate::tests::TestSyncMarker; -use crate::utils::text::suppress_github_mentions; mod command; pub mod comment; @@ -128,25 +127,20 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me MergeType::Auto => pr.db.approver().unwrap_or(""), }; - let mut pr_description = suppress_github_mentions(&pr.github.message); - match &merge_type { - // Strip all PR text for try builds, to avoid useless issue pings on the repository. + let pr_description = match &merge_type { // Only keep any lines starting with `CUSTOM_TRY_JOB_PREFIX`. - MergeType::Try { try_jobs } => { - // If we do not have any custom try jobs, keep the ones that might be in the PR - // description. - pr_description = if try_jobs.is_empty() { - pr_description - .lines() - .map(|l| l.trim()) - .filter(|l| l.starts_with(CUSTOM_TRY_JOB_PREFIX)) - .join("\n") - } else { - // If we do have custom jobs, ignore the original description completely - String::new() - }; - } - MergeType::Auto => {} + // If we do not have any custom try jobs, keep the ones that might be in the PR + // description. + MergeType::Try { try_jobs } if try_jobs.is_empty() => pr + .github + .message + .lines() + .map(|l| l.trim()) + .filter(|l| l.starts_with(CUSTOM_TRY_JOB_PREFIX)) + .join("\n"), + // If we do have custom jobs, ignore the original description completely + MergeType::Try { .. } => String::new(), + MergeType::Auto => pr.github.message.clone(), }; let mut message = format!( diff --git a/src/utils/text.rs b/src/utils/text.rs index 81f7b943..18de5cd9 100644 --- a/src/utils/text.rs +++ b/src/utils/text.rs @@ -1,19 +1,5 @@ -use regex::{Captures, Regex}; use std::borrow::Cow; -/// Replaces github @mentions with backticks to prevent accidental pings -pub fn suppress_github_mentions(text: &str) -> String { - if !text.contains('@') { - return text.to_string(); - } - - let pattern = r"\B(@\S+)"; - - let re = Regex::new(pattern).unwrap(); - re.replace_all(text, |caps: &Captures| format!("`{}`", &caps[1])) - .to_string() -} - /// Pluralizes a piece of text. pub fn pluralize(base: &str, count: usize) -> Cow<'_, str> { if count == 1 { @@ -27,16 +13,6 @@ pub fn pluralize(base: &str, count: usize) -> Cow<'_, str> { mod tests { use super::*; - #[test] - fn test_suppress_github_mentions() { - assert_eq!(suppress_github_mentions("r? @matklad\n"), "r? `@matklad`\n"); - assert_eq!(suppress_github_mentions("@bors r+\n"), "`@bors` r+\n"); - assert_eq!( - suppress_github_mentions("mail@example.com"), - "mail@example.com" - ) - } - #[test] fn pluralize_zero() { assert_eq!(pluralize("foo", 0), "foos");