Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/ownership/codeowners_file_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ fn teams_by_github_team_name(team_file_glob: Vec<String>) -> HashMap<String, Tea
match glob::glob(&glob) {
Ok(paths) => {
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;
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/ownership/file_owner_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
10 changes: 10 additions & 0 deletions tests/fixtures/missing_github_team/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/fixtures/missing_github_team/config/code_ownership.yml
Original file line number Diff line number Diff line change
@@ -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: []
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name: MissingGithub
3 changes: 3 additions & 0 deletions tests/fixtures/missing_github_team/config/teams/good.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name: Good
github:
team: '@GoodTeam'
5 changes: 5 additions & 0 deletions tests/fixtures/missing_github_team/gems/pets/dog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# generated
# next line should be ignored
# @team Payments

class Dog; end
23 changes: 23 additions & 0 deletions tests/missing_github_team_test.rs
Original file line number Diff line number Diff line change
@@ -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<dyn Error>> {
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`")),
)
}