diff --git a/src/ownership/codeowners_file_parser.rs b/src/ownership/codeowners_file_parser.rs index c40410c..bb430fc 100644 --- a/src/ownership/codeowners_file_parser.rs +++ b/src/ownership/codeowners_file_parser.rs @@ -71,10 +71,10 @@ fn teams_by_github_team_name(team_file_glob: Vec) -> HashMap { for path in paths.filter_map(Result::ok) { - let team = match Team::from_team_file_path(path) { + let team = match Team::from_team_file_path(path.clone()) { Ok(team) => team, Err(e) => { - eprintln!("Error parsing team file: {}", e); + eprintln!("Error parsing team file: {e:?}, path: {}", path.display()); continue; } }; diff --git a/src/ownership/file_owner_resolver.rs b/src/ownership/file_owner_resolver.rs index 8b15e38..71e5247 100644 --- a/src/ownership/file_owner_resolver.rs +++ b/src/ownership/file_owner_resolver.rs @@ -116,7 +116,7 @@ fn load_teams(project_root: &Path, team_file_globs: &[String]) -> std::result::R match Team::from_team_file_path(path.clone()) { Ok(team) => teams.push(team), Err(e) => { - eprintln!("Error parsing team file: {}, path: {}", e, path.display()); + eprintln!("Error parsing team file: {e:?}, path: {}", path.display()); continue; } } diff --git a/tests/fixtures/missing_github_team/.github/CODEOWNERS b/tests/fixtures/missing_github_team/.github/CODEOWNERS new file mode 100644 index 0000000..d830891 --- /dev/null +++ b/tests/fixtures/missing_github_team/.github/CODEOWNERS @@ -0,0 +1,10 @@ +# STOP! - DO NOT EDIT THIS FILE MANUALLY +# This file was automatically generated by "bin/codeownership validate". +# +# CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub +# teams. This is useful when developers create Pull Requests since the +# code/file owner is notified. Reference GitHub docs for more details: +# https://help.github.com/en/articles/about-code-owners + +# Match all files to GoodTeam so for-file --from-codeowners hits the parser path +* @GoodTeam diff --git a/tests/fixtures/missing_github_team/config/code_ownership.yml b/tests/fixtures/missing_github_team/config/code_ownership.yml new file mode 100644 index 0000000..060e985 --- /dev/null +++ b/tests/fixtures/missing_github_team/config/code_ownership.yml @@ -0,0 +1,10 @@ +owned_globs: + - "{gems}/**/*.{rb,tsx,erb}" +team_file_glob: + - config/teams/**/*.yml +unbuilt_gems_path: gems +unowned_globs: +vendored_gems: + path: "gems" +cache_directory: tmp/cache/codeowners +ignore_dirs: [] diff --git a/tests/fixtures/missing_github_team/config/teams/bad_team.yml b/tests/fixtures/missing_github_team/config/teams/bad_team.yml new file mode 100644 index 0000000..5217414 --- /dev/null +++ b/tests/fixtures/missing_github_team/config/teams/bad_team.yml @@ -0,0 +1 @@ +name: MissingGithub diff --git a/tests/fixtures/missing_github_team/config/teams/good.yml b/tests/fixtures/missing_github_team/config/teams/good.yml new file mode 100644 index 0000000..d09cbe9 --- /dev/null +++ b/tests/fixtures/missing_github_team/config/teams/good.yml @@ -0,0 +1,3 @@ +name: Good +github: + team: '@GoodTeam' diff --git a/tests/fixtures/missing_github_team/gems/pets/dog.rb b/tests/fixtures/missing_github_team/gems/pets/dog.rb new file mode 100644 index 0000000..0518b82 --- /dev/null +++ b/tests/fixtures/missing_github_team/gems/pets/dog.rb @@ -0,0 +1,5 @@ +# generated +# next line should be ignored +# @team Payments + +class Dog; end diff --git a/tests/missing_github_team_test.rs b/tests/missing_github_team_test.rs new file mode 100644 index 0000000..55b68fd --- /dev/null +++ b/tests/missing_github_team_test.rs @@ -0,0 +1,23 @@ +use predicates::prelude::*; +use std::error::Error; + +mod common; +use common::OutputStream; +use common::run_codeowners; + +// Exercise the code path that skips invalid team files and prints to stderr +// (codeowners_file_parser::teams_by_github_team_name). Uses for-file +// --from-codeowners so the project is not built and the parser globs team +// files; the invalid bad_team.yml is skipped and an error is printed. +// With the fix: stderr contains "Error parsing team file:" and "missing field `github`". +// Without the fix (reverted): stderr only has generic "YAML serialization/deserialization failed". +#[test] +fn test_missing_github_team_in_team_file_is_reported_on_stderr() -> Result<(), Box> { + run_codeowners( + "missing_github_team", + &["for-file", "--from-codeowners", "ruby/foo.rb"], + true, // command succeeds; invalid file is skipped + OutputStream::Stderr, + predicate::str::contains("Error parsing team file:").and(predicate::str::contains("missing field `github`")), + ) +}