Skip to content
Merged
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
29 changes: 19 additions & 10 deletions src/handlers/mentions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub(super) async fn parse_input(
// Only mentions byte-for-byte matching content inside the patch.
files
.iter()
.filter(|f| patch_contains(&f.patch, &**entry))
.filter(|f| patch_adds(&f.patch, &**entry))
.map(|f| PathBuf::from(&f.filename))
.collect()
}
Expand Down Expand Up @@ -157,11 +157,9 @@ pub(super) async fn handle_input(
Ok(())
}

fn patch_contains(patch: &str, needle: &str) -> bool {
fn patch_adds(patch: &str, needle: &str) -> bool {
for line in patch.lines() {
if (!line.starts_with("+++") && line.starts_with('+'))
|| (!line.starts_with("---") && line.starts_with('-'))
{
if !line.starts_with("+++") && line.starts_with('+') {
if line.contains(needle) {
return true;
}
Expand All @@ -183,18 +181,29 @@ mod tests {
+hello world
context line
";
assert!(patch_contains(patch, "hello"));
assert!(patch_adds(patch, "hello"));
}

#[test]
fn finds_removed_line() {
fn finds_added_line_in_modified() {
let patch = "\
--- a/file.txt
+++ b/file.txt
-hello
+hello world
";
assert!(patch_adds(patch, "hello"));
}

#[test]
fn ignore_removed_line() {
let patch = "\
--- a/file.txt
+++ b/file.txt
-old value
+new value
";
assert!(patch_contains(patch, "old value"));
assert!(!patch_adds(patch, "old value"));
}

#[test]
Expand All @@ -204,7 +213,7 @@ mod tests {
+++ b/file.txt
context line
";
assert!(!patch_contains(patch, "file.txt")); // should *not* match header
assert!(!patch_adds(patch, "file.txt")); // should *not* match header
}

#[test]
Expand All @@ -214,6 +223,6 @@ mod tests {
+++ b/file.txt
+added line
";
assert!(!patch_contains(patch, "missing"));
assert!(!patch_adds(patch, "missing"));
}
}
Loading