Skip to content

Commit 64176cb

Browse files
authored
Merge pull request #457 from bncer/ping-username-commits
Get rid of username notification checker in merge commit messages
2 parents 1a0c99f + ac5a8ff commit 64176cb

File tree

2 files changed

+13
-43
lines changed

2 files changed

+13
-43
lines changed

src/bors/mod.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::github::api::client::GithubRepositoryClient;
1818
use crate::permissions::UserPermissions;
1919
#[cfg(test)]
2020
use crate::tests::TestSyncMarker;
21-
use crate::utils::text::suppress_github_mentions;
2221

2322
mod command;
2423
pub mod comment;
@@ -128,25 +127,20 @@ pub fn create_merge_commit_message(pr: handlers::PullRequestData, merge_type: Me
128127
MergeType::Auto => pr.db.approver().unwrap_or("<unknown>"),
129128
};
130129

131-
let mut pr_description = suppress_github_mentions(&pr.github.message);
132-
match &merge_type {
133-
// Strip all PR text for try builds, to avoid useless issue pings on the repository.
130+
let pr_description = match &merge_type {
134131
// Only keep any lines starting with `CUSTOM_TRY_JOB_PREFIX`.
135-
MergeType::Try { try_jobs } => {
136-
// If we do not have any custom try jobs, keep the ones that might be in the PR
137-
// description.
138-
pr_description = if try_jobs.is_empty() {
139-
pr_description
140-
.lines()
141-
.map(|l| l.trim())
142-
.filter(|l| l.starts_with(CUSTOM_TRY_JOB_PREFIX))
143-
.join("\n")
144-
} else {
145-
// If we do have custom jobs, ignore the original description completely
146-
String::new()
147-
};
148-
}
149-
MergeType::Auto => {}
132+
// If we do not have any custom try jobs, keep the ones that might be in the PR
133+
// description.
134+
MergeType::Try { try_jobs } if try_jobs.is_empty() => pr
135+
.github
136+
.message
137+
.lines()
138+
.map(|l| l.trim())
139+
.filter(|l| l.starts_with(CUSTOM_TRY_JOB_PREFIX))
140+
.join("\n"),
141+
// If we do have custom jobs, ignore the original description completely
142+
MergeType::Try { .. } => String::new(),
143+
MergeType::Auto => pr.github.message.clone(),
150144
};
151145

152146
let mut message = format!(

src/utils/text.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
use regex::{Captures, Regex};
21
use std::borrow::Cow;
32

4-
/// Replaces github @mentions with backticks to prevent accidental pings
5-
pub fn suppress_github_mentions(text: &str) -> String {
6-
if !text.contains('@') {
7-
return text.to_string();
8-
}
9-
10-
let pattern = r"\B(@\S+)";
11-
12-
let re = Regex::new(pattern).unwrap();
13-
re.replace_all(text, |caps: &Captures| format!("`{}`", &caps[1]))
14-
.to_string()
15-
}
16-
173
/// Pluralizes a piece of text.
184
pub fn pluralize(base: &str, count: usize) -> Cow<'_, str> {
195
if count == 1 {
@@ -27,16 +13,6 @@ pub fn pluralize(base: &str, count: usize) -> Cow<'_, str> {
2713
mod tests {
2814
use super::*;
2915

30-
#[test]
31-
fn test_suppress_github_mentions() {
32-
assert_eq!(suppress_github_mentions("r? @matklad\n"), "r? `@matklad`\n");
33-
assert_eq!(suppress_github_mentions("@bors r+\n"), "`@bors` r+\n");
34-
assert_eq!(
35-
suppress_github_mentions("[email protected]"),
36-
37-
)
38-
}
39-
4016
#[test]
4117
fn pluralize_zero() {
4218
assert_eq!(pluralize("foo", 0), "foos");

0 commit comments

Comments
 (0)