From 727fb95abe09ff3a6699634aa720325b525b0388 Mon Sep 17 00:00:00 2001 From: Perry Hertler Date: Fri, 8 Nov 2024 09:15:07 -0600 Subject: [PATCH] version 0.2.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/ownership/validator.rs | 20 ++++++++++++-------- tests/invalid_project_test.rs | 2 +- tests/valid_project_test.rs | 3 ++- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9a0539d..c2a34cd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -162,7 +162,7 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "codeowners" -version = "0.2.0" +version = "0.2.1" dependencies = [ "assert_cmd", "clap", diff --git a/Cargo.toml b/Cargo.toml index 3260220..c27b74f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "codeowners" -version = "0.2.0" +version = "0.2.1" edition = "2021" [profile.release] diff --git a/src/ownership/validator.rs b/src/ownership/validator.rs index 35d970e..6612e73 100644 --- a/src/ownership/validator.rs +++ b/src/ownership/validator.rs @@ -174,14 +174,18 @@ impl Error { match self { Error::FileWithoutOwner { path } => vec![format!("- {}", path.to_string_lossy())], Error::FileWithMultipleOwners { path, owners } => { - let mut output = vec![format!("\n{}", path.to_string_lossy().to_string())]; - for owner in owners.iter().sorted_by_key(|owner| owner.team_name.to_lowercase()) { - output.push(format!(" owner: {}", owner.team_name)); - for source in &owner.sources { - output.push(format!(" - {}", source)); - } - } - vec![output.join("\n")] + let path_display = path.to_string_lossy(); + let mut messages = vec![format!("\n{path_display}")]; + + owners + .iter() + .sorted_by_key(|owner| owner.team_name.to_lowercase()) + .for_each(|owner| { + messages.push(format!(" owner: {}", owner.team_name)); + messages.extend(owner.sources.iter().map(|source| format!(" - {source}"))); + }); + + vec![messages.join("\n")] } Error::CodeownershipFileIsStale => vec![], Error::InvalidTeam { name, path } => vec![format!("- {} is referencing an invalid team - '{}'", path.to_string_lossy(), name)], diff --git a/tests/invalid_project_test.rs b/tests/invalid_project_test.rs index 8588899..e63c683 100644 --- a/tests/invalid_project_test.rs +++ b/tests/invalid_project_test.rs @@ -79,4 +79,4 @@ fn test_for_file_multiple_owners() -> Result<(), Box> { - Owner specified in `ruby/app/services/.codeowner` "})); Ok(()) -} +} diff --git a/tests/valid_project_test.rs b/tests/valid_project_test.rs index 350e929..7da5ab4 100644 --- a/tests/valid_project_test.rs +++ b/tests/valid_project_test.rs @@ -46,7 +46,8 @@ fn test_for_file() -> Result<(), Box> { .stdout(predicate::eq(indoc! {" Team: Payroll Team YML: config/teams/payroll.yml - Description: Owner annotation at the top of the file + Description: + - Owner annotation at the top of the file "})); Ok(()) }