Skip to content

Commit e3be101

Browse files
committed
Only look at added lines in mentions type="content"
1 parent f568bf7 commit e3be101

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/handlers/mentions.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub(super) async fn parse_input(
8080
// Only mentions byte-for-byte matching content inside the patch.
8181
files
8282
.iter()
83-
.filter(|f| patch_contains(&f.patch, &**entry))
83+
.filter(|f| patch_adds(&f.patch, &**entry))
8484
.map(|f| PathBuf::from(&f.filename))
8585
.collect()
8686
}
@@ -157,11 +157,9 @@ pub(super) async fn handle_input(
157157
Ok(())
158158
}
159159

160-
fn patch_contains(patch: &str, needle: &str) -> bool {
160+
fn patch_adds(patch: &str, needle: &str) -> bool {
161161
for line in patch.lines() {
162-
if (!line.starts_with("+++") && line.starts_with('+'))
163-
|| (!line.starts_with("---") && line.starts_with('-'))
164-
{
162+
if !line.starts_with("+++") && line.starts_with('+') {
165163
if line.contains(needle) {
166164
return true;
167165
}
@@ -183,18 +181,29 @@ mod tests {
183181
+hello world
184182
context line
185183
";
186-
assert!(patch_contains(patch, "hello"));
184+
assert!(patch_adds(patch, "hello"));
187185
}
188186

189187
#[test]
190-
fn finds_removed_line() {
188+
fn finds_added_line_in_modified() {
189+
let patch = "\
190+
--- a/file.txt
191+
+++ b/file.txt
192+
-hello
193+
+hello world
194+
";
195+
assert!(patch_adds(patch, "hello"));
196+
}
197+
198+
#[test]
199+
fn ignore_removed_line() {
191200
let patch = "\
192201
--- a/file.txt
193202
+++ b/file.txt
194203
-old value
195204
+new value
196205
";
197-
assert!(patch_contains(patch, "old value"));
206+
assert!(!patch_adds(patch, "old value"));
198207
}
199208

200209
#[test]
@@ -204,7 +213,7 @@ mod tests {
204213
+++ b/file.txt
205214
context line
206215
";
207-
assert!(!patch_contains(patch, "file.txt")); // should *not* match header
216+
assert!(!patch_adds(patch, "file.txt")); // should *not* match header
208217
}
209218

210219
#[test]
@@ -214,6 +223,6 @@ mod tests {
214223
+++ b/file.txt
215224
+added line
216225
";
217-
assert!(!patch_contains(patch, "missing"));
226+
assert!(!patch_adds(patch, "missing"));
218227
}
219228
}

0 commit comments

Comments
 (0)