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
15 changes: 15 additions & 0 deletions src/ownership/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ impl Validator {

errors.append(&mut self.invalid_team_annotation(&team_names));
errors.append(&mut self.invalid_package_ownership(&team_names));
errors.append(&mut self.invalid_directory_ownership(&team_names));

errors
}
Expand Down Expand Up @@ -107,6 +108,20 @@ impl Validator {
.collect()
}

/// `DirectoryMapper::entries` skips unresolvable owners, so the directory silently
/// inherits its ancestor's owner and nothing else reports the bad name.
fn invalid_directory_ownership(&self, team_names: &HashSet<&TeamName>) -> Vec<Error> {
self.project
.directory_codeowner_files
.iter()
.filter(|directory_codeowner_file| !team_names.contains(&directory_codeowner_file.owner))
.map(|directory_codeowner_file| Error::InvalidTeam {
name: directory_codeowner_file.owner.clone(),
path: self.project.relative_path(&directory_codeowner_file.path).to_owned(),
})
.collect()
}

fn validate_file_ownership(&self) -> Vec<Error> {
let mut validation_errors = Vec::new();

Expand Down
14 changes: 14 additions & 0 deletions tests/fixtures/invalid-directory-codeowner/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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


# Owner in .codeowner
/app/services/**/** @footeam

# Team YML ownership
/config/teams/foo.yml @footeam
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Foo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Web3
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class NestedFile
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
owned_globs:
- "{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml}"
unowned_globs:
- config/code_ownership.yml
javascript_package_paths:
- javascript/packages/**
vendored_gems_path: gems
team_file_glob:
- config/teams/**/*.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: Foo
github:
team: "@footeam"
members:
- fooer
25 changes: 25 additions & 0 deletions tests/invalid_directory_codeowner_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use indoc::indoc;
use predicates::prelude::*;
use std::error::Error;

mod common;
use common::OutputStream;
use common::run_codeowners;

/// A nested `.codeowner` naming an unregistered team, under one naming a real team:
/// ownership falls through to the ancestor, so nothing else reports the bad name.
#[test]
fn test_validate_reports_directory_codeowner_with_invalid_team() -> Result<(), Box<dyn Error>> {
run_codeowners(
"invalid-directory-codeowner",
&["validate"],
false,
OutputStream::Stdout,
predicate::str::contains(indoc! {"
Found invalid team annotations
- app/services/nested/.codeowner is referencing an invalid team - 'Web3'
"}),
)?;

Ok(())
}