Skip to content

Commit 55832fc

Browse files
authored
simplifying file_owner_for_file (#77)
1 parent 8734913 commit 55832fc

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codeowners"
3-
version = "0.2.13"
3+
version = "0.2.14"
44
edition = "2024"
55

66
[profile.release]

src/ownership.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use self::{
3333
pub struct Ownership {
3434
project: Arc<Project>,
3535
}
36-
#[derive(Debug)]
36+
#[derive(Debug, Clone)]
3737
pub struct FileOwner {
3838
pub team: Team,
3939
pub team_config_file_path: String,

src/runner.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ pub fn for_file(run_config: &RunConfig, file_path: &str, from_codeowners: bool)
4343
for_file_optimized(run_config, file_path)
4444
}
4545

46-
pub fn file_owners_for_file(run_config: &RunConfig, file_path: &str) -> Result<Vec<FileOwner>, Error> {
46+
pub fn file_owner_for_file(run_config: &RunConfig, file_path: &str) -> Result<Option<FileOwner>, Error> {
4747
let config = config_from_path(&run_config.config_path)?;
4848
use crate::ownership::for_file_fast::find_file_owners;
4949
let owners = find_file_owners(&run_config.project_root, &config, std::path::Path::new(file_path)).map_err(Error::Io)?;
50-
51-
Ok(owners)
50+
Ok(owners.first().cloned())
5251
}
5352

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

5958
pub fn version() -> String {
@@ -382,13 +381,14 @@ mod tests {
382381
no_cache: false,
383382
};
384383

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

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

0 commit comments

Comments
 (0)