Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codeowners"
version = "0.2.13"
version = "0.2.14"
edition = "2024"

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion src/ownership.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use self::{
pub struct Ownership {
project: Arc<Project>,
}
#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct FileOwner {
pub team: Team,
pub team_config_file_path: String,
Expand Down
24 changes: 12 additions & 12 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ pub fn for_file(run_config: &RunConfig, file_path: &str, from_codeowners: bool)
for_file_optimized(run_config, file_path)
}

pub fn file_owners_for_file(run_config: &RunConfig, file_path: &str) -> Result<Vec<FileOwner>, Error> {
pub fn file_owner_for_file(run_config: &RunConfig, file_path: &str) -> Result<Option<FileOwner>, Error> {
let config = config_from_path(&run_config.config_path)?;
use crate::ownership::for_file_fast::find_file_owners;
let owners = find_file_owners(&run_config.project_root, &config, std::path::Path::new(file_path)).map_err(Error::Io)?;

Ok(owners)
Ok(owners.first().cloned())
}

pub fn team_for_file(run_config: &RunConfig, file_path: &str) -> Result<Option<Team>, Error> {
let owners = file_owners_for_file(run_config, file_path)?;
Ok(owners.first().map(|fo| fo.team.clone()))
let owner = file_owner_for_file(run_config, file_path)?;
Ok(owner.map(|fo| fo.team.clone()))
}

pub fn version() -> String {
Expand Down Expand Up @@ -382,13 +381,14 @@ mod tests {
no_cache: false,
};

let file_owners = file_owners_for_file(&run_config, "app/consumers/deep/nesting/nestdir/deep_file.rb").unwrap();
assert_eq!(file_owners.len(), 1);
assert_eq!(file_owners[0].team.name, "b");
assert_eq!(file_owners[0].team.github_team, "@b");
assert!(file_owners[0].team.path.to_string_lossy().ends_with("config/teams/b.yml"));
assert_eq!(file_owners[0].sources.len(), 1);
assert_eq!(file_owners[0].sources, vec![Source::AnnotatedFile]);
let file_owner = file_owner_for_file(&run_config, "app/consumers/deep/nesting/nestdir/deep_file.rb")
.unwrap()
.unwrap();
assert_eq!(file_owner.team.name, "b");
assert_eq!(file_owner.team.github_team, "@b");
assert!(file_owner.team.path.to_string_lossy().ends_with("config/teams/b.yml"));
assert_eq!(file_owner.sources.len(), 1);
assert_eq!(file_owner.sources, vec![Source::AnnotatedFile]);

let team = team_for_file(&run_config, "app/consumers/deep/nesting/nestdir/deep_file.rb")
.unwrap()
Expand Down