Skip to content

Commit 18cd774

Browse files
authored
fix: error message when github team name is missing from team config (#96)
1 parent 50fdfa8 commit 18cd774

8 files changed

Lines changed: 55 additions & 3 deletions

File tree

src/ownership/codeowners_file_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ fn teams_by_github_team_name(team_file_glob: Vec<String>) -> HashMap<String, Tea
7171
match glob::glob(&glob) {
7272
Ok(paths) => {
7373
for path in paths.filter_map(Result::ok) {
74-
let team = match Team::from_team_file_path(path) {
74+
let team = match Team::from_team_file_path(path.clone()) {
7575
Ok(team) => team,
7676
Err(e) => {
77-
eprintln!("Error parsing team file: {}", e);
77+
eprintln!("Error parsing team file: {e:?}, path: {}", path.display());
7878
continue;
7979
}
8080
};

src/ownership/file_owner_resolver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn load_teams(project_root: &Path, team_file_globs: &[String]) -> std::result::R
116116
match Team::from_team_file_path(path.clone()) {
117117
Ok(team) => teams.push(team),
118118
Err(e) => {
119-
eprintln!("Error parsing team file: {}, path: {}", e, path.display());
119+
eprintln!("Error parsing team file: {e:?}, path: {}", path.display());
120120
continue;
121121
}
122122
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# STOP! - DO NOT EDIT THIS FILE MANUALLY
2+
# This file was automatically generated by "bin/codeownership validate".
3+
#
4+
# CODEOWNERS is used for GitHub to suggest code/file owners to various GitHub
5+
# teams. This is useful when developers create Pull Requests since the
6+
# code/file owner is notified. Reference GitHub docs for more details:
7+
# https://help.github.com/en/articles/about-code-owners
8+
9+
# Match all files to GoodTeam so for-file --from-codeowners hits the parser path
10+
* @GoodTeam
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
owned_globs:
2+
- "{gems}/**/*.{rb,tsx,erb}"
3+
team_file_glob:
4+
- config/teams/**/*.yml
5+
unbuilt_gems_path: gems
6+
unowned_globs:
7+
vendored_gems:
8+
path: "gems"
9+
cache_directory: tmp/cache/codeowners
10+
ignore_dirs: []
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
name: MissingGithub
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: Good
2+
github:
3+
team: '@GoodTeam'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# generated
2+
# next line should be ignored
3+
# @team Payments
4+
5+
class Dog; end

tests/missing_github_team_test.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use predicates::prelude::*;
2+
use std::error::Error;
3+
4+
mod common;
5+
use common::OutputStream;
6+
use common::run_codeowners;
7+
8+
// Exercise the code path that skips invalid team files and prints to stderr
9+
// (codeowners_file_parser::teams_by_github_team_name). Uses for-file
10+
// --from-codeowners so the project is not built and the parser globs team
11+
// files; the invalid bad_team.yml is skipped and an error is printed.
12+
// With the fix: stderr contains "Error parsing team file:" and "missing field `github`".
13+
// Without the fix (reverted): stderr only has generic "YAML serialization/deserialization failed".
14+
#[test]
15+
fn test_missing_github_team_in_team_file_is_reported_on_stderr() -> Result<(), Box<dyn Error>> {
16+
run_codeowners(
17+
"missing_github_team",
18+
&["for-file", "--from-codeowners", "ruby/foo.rb"],
19+
true, // command succeeds; invalid file is skipped
20+
OutputStream::Stderr,
21+
predicate::str::contains("Error parsing team file:").and(predicate::str::contains("missing field `github`")),
22+
)
23+
}

0 commit comments

Comments
 (0)