Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions src/bors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -128,25 +127,20 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
MergeType::Auto => pr.db.approver().unwrap_or("<unknown>"),
};

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!(
Expand Down
24 changes: 0 additions & 24 deletions src/utils/text.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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");
Expand Down