Skip to content

Commit

Permalink
find: compute the root of the provided filepaths
Browse files Browse the repository at this point in the history
This commit changes on how we scan and resolve filepaths
relative to the `CODEOWNERS` by computing the common ancestor
between all of the provided paths so that we can correctly
resolve file paths.
  • Loading branch information
feds01 committed Feb 2, 2025
1 parent 7ad4913 commit cd8653c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crates/teamsearch/src/commands/find.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Implementation of the `find` command.
use std::path::PathBuf;
use std::{iter::once, path::PathBuf};

use anyhow::Result;
use derive_more::Constructor;
Expand Down Expand Up @@ -30,15 +30,17 @@ pub(crate) fn find(
pattern: String,
case_sensitive: bool,
) -> Result<FindResult> {
let paths: Vec<PathBuf> = files.iter().map(fs::normalize_path).unique().collect();
let paths: Vec<PathBuf> =
files.iter().chain(once(&settings.codeowners)).map(fs::normalize_path).unique().collect();
let root = fs::common_root(&paths);

if paths.is_empty() {
return Ok(FindResult::default());
}

// We've gotta parse in the `CODEOWNERS` file, and then
// extract the given patterns that are specified for the particular team.
let codeowners = CodeOwners::parse_from_file(&settings.codeowners, &paths[0])?;
let codeowners = CodeOwners::parse_from_file(&settings.codeowners, &root)?;

let teams = team.iter().filter(|t| codeowners.has_team(t)).unique().collect::<Vec<_>>();

Expand Down

0 comments on commit cd8653c

Please sign in to comment.