Skip to content

Commit f0079de

Browse files
committed
feat: use AND not OR to filter repos
1 parent b7e7508 commit f0079de

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/config/loader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,11 +573,11 @@ mod tests {
573573

574574
// Test include and exclude together
575575
let filtered = config.filter_repositories(
576-
&["web".to_string(), "api".to_string()], // include web OR api
577-
&["frontend".to_string()], // but exclude frontend
576+
&["backend".to_string(), "api".to_string()], // include backend AND api (only repo2 has both)
577+
&["frontend".to_string()], // but exclude frontend
578578
None,
579579
);
580580
assert_eq!(filtered.len(), 1);
581-
assert_eq!(filtered[0].name, "repo2"); // repo2 has api but not frontend
581+
assert_eq!(filtered[0].name, "repo2"); // repo2 has backend AND api, not frontend
582582
}
583583
}

src/utils/filters.rs

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ pub fn filter_repositories(
7272
base_repos
7373
.into_iter()
7474
.filter(|repo| {
75-
// Check inclusion filter: if include_tags is empty, include all; otherwise check if repo has any included tag
75+
// Check inclusion filter: if include_tags is empty, include all; otherwise check if repo has all included tags (AND logic)
7676
let included =
77-
include_tags.is_empty() || include_tags.iter().any(|tag| repo.has_tag(tag));
77+
include_tags.is_empty() || include_tags.iter().all(|tag| repo.has_tag(tag));
7878

7979
// Check exclusion filter: if exclude_tags is empty, exclude none; otherwise check if repo has any excluded tag
8080
let excluded =
@@ -212,12 +212,12 @@ mod tests {
212212
// Test include and exclude together
213213
let filtered = filter_repositories(
214214
&repos,
215-
&["web".to_string(), "api".to_string()], // include web OR api
216-
&["frontend".to_string()], // but exclude frontend
215+
&["web".to_string(), "frontend".to_string()], // include web AND frontend (only repo1 has both)
216+
&["backend".to_string()], // but exclude backend
217217
None,
218218
);
219219
assert_eq!(filtered.len(), 1);
220-
assert_eq!(filtered[0].name, "repo2"); // repo2 has api but not frontend
220+
assert_eq!(filtered[0].name, "repo1"); // repo1 has web AND frontend, not backend
221221
}
222222

223223
#[test]
@@ -237,4 +237,32 @@ mod tests {
237237
assert_eq!(filtered.len(), 1);
238238
assert_eq!(filtered[0].name, "repo1");
239239
}
240+
241+
#[test]
242+
fn test_filter_repositories_and_logic_with_multiple_tags() {
243+
let repos = create_test_repositories();
244+
245+
// Multiple tags should use AND logic - all tags must be present
246+
let filtered = filter_repositories(
247+
&repos,
248+
&["frontend".to_string(), "web".to_string()], // both tags required
249+
&[],
250+
None,
251+
);
252+
assert_eq!(filtered.len(), 1);
253+
assert_eq!(filtered[0].name, "repo1"); // Only repo1 has both tags
254+
255+
// If one tag doesn't exist, no repos should match
256+
let filtered = filter_repositories(
257+
&repos,
258+
&["frontend".to_string(), "nonexistent".to_string()],
259+
&[],
260+
None,
261+
);
262+
assert_eq!(filtered.len(), 0);
263+
264+
// Single nonexistent tag should return no repos
265+
let filtered = filter_repositories(&repos, &["nonexistent".to_string()], &[], None);
266+
assert_eq!(filtered.len(), 0);
267+
}
240268
}

0 commit comments

Comments
 (0)