@@ -5,7 +5,7 @@ use ignore::{
55use std:: path:: { Path , PathBuf } ;
66use utils:: error:: { Error , Result } ;
77
8- use crate :: types:: { CodeownersEntry , Owner , OwnerType , Tag } ;
8+ use crate :: types:: { CodeownersEntry , FileEntry , Owner , OwnerType , Tag } ;
99
1010/// Find CODEOWNERS files recursively in the given directory and its subdirectories
1111pub fn find_codeowners_files < P : AsRef < Path > > ( base_path : P ) -> Result < Vec < PathBuf > > {
@@ -313,6 +313,50 @@ pub fn find_tags_for_file(file_path: &Path, entries: &[CodeownersEntry]) -> Resu
313313 . unwrap_or_default ( ) )
314314}
315315
316+ /// Find all files owned by a specific owner
317+ pub fn find_files_for_owner ( files : & [ FileEntry ] , owner : & Owner ) -> Vec < PathBuf > {
318+ files
319+ . iter ( )
320+ . filter ( |file_entry| file_entry. owners . contains ( owner) )
321+ . map ( |file_entry| file_entry. path . clone ( ) )
322+ . collect ( )
323+ }
324+
325+ /// Find all files tagged with a specific tag
326+ pub fn find_files_for_tag ( files : & [ FileEntry ] , tag : & Tag ) -> Vec < PathBuf > {
327+ files
328+ . iter ( )
329+ . filter ( |file_entry| file_entry. tags . contains ( tag) )
330+ . map ( |file_entry| file_entry. path . clone ( ) )
331+ . collect ( )
332+ }
333+
334+ /// Collect all unique owners from CODEOWNERS entries
335+ pub fn collect_owners ( entries : & [ CodeownersEntry ] ) -> Vec < Owner > {
336+ let mut owners = std:: collections:: HashSet :: new ( ) ;
337+
338+ for entry in entries {
339+ for owner in & entry. owners {
340+ owners. insert ( owner. clone ( ) ) ;
341+ }
342+ }
343+
344+ owners. into_iter ( ) . collect ( )
345+ }
346+
347+ /// Collect all unique tags from CODEOWNERS entries
348+ pub fn collect_tags ( entries : & [ CodeownersEntry ] ) -> Vec < Tag > {
349+ let mut tags = std:: collections:: HashSet :: new ( ) ;
350+
351+ for entry in entries {
352+ for tag in & entry. tags {
353+ tags. insert ( tag. clone ( ) ) ;
354+ }
355+ }
356+
357+ tags. into_iter ( ) . collect ( )
358+ }
359+
316360#[ cfg( test) ]
317361mod tests {
318362 use super :: * ;
0 commit comments