diff --git a/src/ownership.rs b/src/ownership.rs index bcfe212..fc296cc 100644 --- a/src/ownership.rs +++ b/src/ownership.rs @@ -14,7 +14,10 @@ mod file_owner_finder; pub(crate) mod mapper; mod validator; -use crate::{ownership::mapper::DirectoryMapper, project::Project}; +use crate::{ + ownership::mapper::DirectoryMapper, + project::{Project, Team}, +}; pub use validator::Errors as ValidatorErrors; @@ -29,7 +32,7 @@ pub struct Ownership { } pub struct FileOwner { - pub team_name: TeamName, + pub team: Team, pub team_config_file_path: String, pub sources: Vec, } @@ -64,8 +67,8 @@ impl Display for FileOwner { write!( f, - "Team: {}\nTeam YML: {}\nDescription:\n- {}", - self.team_name, self.team_config_file_path, sources + "Team: {}\nGithub Team: {}\nTeam YML: {}\nDescription:\n- {}", + self.team.name, self.team.github_team, self.team_config_file_path, sources ) } } @@ -73,8 +76,12 @@ impl Display for FileOwner { impl Default for FileOwner { fn default() -> Self { Self { - team_name: "Unowned".to_string(), - team_config_file_path: "Unowned".to_string(), + team: Team { + name: "Unowned".to_string(), + github_team: "Unowned".to_string(), + ..Default::default() + }, + team_config_file_path: "".to_string(), sources: vec![], } } @@ -132,7 +139,7 @@ impl Ownership { .sorted_by_key(|owner| owner.team_name.to_lowercase()) .map(|owner| match self.project.get_team(&owner.team_name) { Some(team) => FileOwner { - team_name: owner.team_name.clone(), + team: team.clone(), team_config_file_path: team .path .strip_prefix(&self.project.base_path) @@ -220,7 +227,7 @@ mod tests { let ownership = build_ownership_with_all_mappers()?; let file_owners = ownership.for_file("app/consumers/directory_owned.rb").unwrap(); assert_eq!(file_owners.len(), 1); - assert_eq!(file_owners[0].team_name, "Bar"); + assert_eq!(file_owners[0].team.name, "Bar"); assert_eq!(file_owners[0].team_config_file_path, "config/teams/bar.yml"); Ok(()) } diff --git a/src/project.rs b/src/project.rs index 9b9a07d..0ef1728 100644 --- a/src/project.rs +++ b/src/project.rs @@ -29,7 +29,7 @@ pub struct ProjectFile { pub path: PathBuf, } -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct Team { pub path: PathBuf, pub name: String, diff --git a/tests/invalid_project_test.rs b/tests/invalid_project_test.rs index 92ca132..95fba8c 100644 --- a/tests/invalid_project_test.rs +++ b/tests/invalid_project_test.rs @@ -53,7 +53,8 @@ fn test_for_file() -> Result<(), Box> { .success() .stdout(predicate::eq(indoc! {" Team: Unowned - Team YML: Unowned + Github Team: Unowned + Team YML: Description: - Unowned "})); @@ -72,13 +73,15 @@ fn test_for_file_multiple_owners() -> Result<(), Box> { .success() .stdout(predicate::eq(indoc! {" Error: file is owned by multiple teams! - + Team: Payments + Github Team: @PaymentTeam Team YML: config/teams/payments.yml Description: - Owner annotation at the top of the file - + Team: Payroll + Github Team: @PayrollTeam Team YML: config/teams/payroll.yml Description: - Owner specified in `ruby/app/services/.codeowner` diff --git a/tests/valid_project_test.rs b/tests/valid_project_test.rs index 2231d4a..a781476 100644 --- a/tests/valid_project_test.rs +++ b/tests/valid_project_test.rs @@ -48,6 +48,7 @@ fn test_for_file() -> Result<(), Box> { .success() .stdout(predicate::eq(indoc! {" Team: Payroll + Github Team: @PayrollTeam Team YML: config/teams/payroll.yml Description: - Owner annotation at the top of the file @@ -67,6 +68,7 @@ fn test_for_file_same_team_multiple_ownerships() -> Result<(), Box> { .success() .stdout(predicate::eq(indoc! {" Team: Payroll + Github Team: @PayrollTeam Team YML: config/teams/payroll.yml Description: - Owner annotation at the top of the file @@ -87,6 +89,7 @@ fn test_for_file_with_2_ownerships() -> Result<(), Box> { .success() .stdout(predicate::eq(indoc! {" Team: Payroll + Github Team: @PayrollTeam Team YML: config/teams/payroll.yml Description: - Owner annotation at the top of the file