Skip to content
Merged
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
8 changes: 7 additions & 1 deletion src/ownership.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,11 +26,17 @@ pub struct Entry {
pub path: String,
pub github_team: String,
pub team_name: String,
pub disabled: bool,
}

impl Entry {
fn to_row(&self) -> String {
format!("/{} {}", self.path, self.github_team)
let line = format!("/{} {}", self.path, self.github_team);
if self.disabled {
format!("# {}", line)
} else {
line
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/ownership/mapper/package_mapper.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -73,14 +73,11 @@ impl PackageMapper {
let team = team_by_name.get(&package.owner);

if let Some(team) = team {
if team.avoid_ownership {
continue;
}

entries.push(Entry {
path: format!("{}/**/**", package_root),
github_team: team.github_team.to_owned(),
team_name: team.name.to_owned(),
disabled: team.avoid_ownership,
});
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/ownership/mapper/team_file_mapper.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,16 +26,13 @@ impl Mapper for TeamFileMapper {
let team = team_by_name.get(owner);

if let Some(team) = team {
if team.avoid_ownership {
continue;
}

let relative_path = self.project.relative_path(&owned_file.path);

entries.push(Entry {
path: relative_path.to_string_lossy().to_string(),
github_team: team.github_team.to_owned(),
team_name: team.name.to_owned(),
disabled: team.avoid_ownership,
});
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/ownership/mapper/team_gem_mapper.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,15 +19,16 @@ impl Mapper for TeamGemMapper {
let vendored_gem_by_name = self.project.vendored_gem_by_name();
let mut entries: Vec<Entry> = Vec::new();

for team in self.project.teams.iter().filter(|team| !team.avoid_ownership) {
for team in &self.project.teams {
for owned_gem in &team.owned_gems {
let vendored_gem = vendored_gem_by_name.get(owned_gem);

if let Some(vendored_gem) = vendored_gem {
entries.push(Entry {
path: self.project.relative_path(&vendored_gem.path).to_string_lossy().to_string(),
path: format!("{}/**/**", self.project.relative_path(&vendored_gem.path).to_string_lossy()),
github_team: team.github_team.to_owned(),
team_name: team.name.to_owned(),
disabled: team.avoid_ownership,
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ownership/mapper/team_glob_mapper.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,12 +18,13 @@ impl Mapper for TeamGlobMapper {
fn entries(&self) -> Vec<Entry> {
let mut entries: Vec<Entry> = Vec::new();

for team in self.project.teams.iter().filter(|team| !team.avoid_ownership) {
for team in &self.project.teams {
for owned_glob in &team.owned_globs {
entries.push(Entry {
path: owned_glob.to_owned(),
github_team: team.github_team.to_owned(),
team_name: team.name.to_owned(),
disabled: team.avoid_ownership,
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/ownership/mapper/team_yml_mapper.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -20,11 +20,12 @@ impl Mapper for TeamYmlMapper {
fn entries(&self) -> Vec<Entry> {
let mut entries: Vec<Entry> = Vec::new();

for team in self.project.teams.iter().filter(|team| !team.avoid_ownership) {
for team in &self.project.teams {
entries.push(Entry {
path: self.project.relative_path(&team.path).to_string_lossy().to_string(),
github_team: team.github_team.to_owned(),
team_name: team.name.to_owned(),
disabled: team.avoid_ownership,
});
}

Expand Down
6 changes: 1 addition & 5 deletions src/ownership/tests.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,7 +47,6 @@ fn build_project_with_annotated_file() -> Project {
packages: vec![],
teams: vec![build_payroll_team()],
vendored_gems: vec![],
unowned_globs: vec![],
codeowners_file: "".to_owned(),
}
}
Expand All@@ -70,7 +69,6 @@ fn build_project_with_team_specific_owned_globs() -> Project {
packages: vec![],
teams: vec![build_payroll_team_with_owned_glob()],
vendored_gems: vec![],
unowned_globs: vec![],
codeowners_file: "".to_owned(),
}
}
Expand All@@ -93,7 +91,6 @@ fn build_project_with_packages() -> Project {
],
teams: vec![build_payroll_team()],
vendored_gems: vec![],
unowned_globs: vec![],
codeowners_file: "".to_owned(),
}
}
Expand All@@ -108,7 +105,6 @@ fn build_project_with_team_owned_gems() -> Project {
path: Path::new("components/payroll_calculator").to_owned(),
name: "payroll_calculator".to_owned(),
}],
unowned_globs: vec![],
codeowners_file: "".to_owned(),
}
}
Expand DownExpand Up@@ -211,7 +207,7 @@ fn test_team_owned_gems() {
"/config/teams/payroll.yml @Payroll-Eng",
"",
"# Team owned gems",
"/components/payroll_calculator @Payroll-Eng",
"/components/payroll_calculator/**/** @Payroll-Eng",
"",
])
.join("\n")
Expand Down
5 changes: 0 additions & 5 deletions src/ownership/validator.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -148,11 +148,6 @@ impl Validator {
.par_iter()
.filter_map(|project_file| {
let mut owners_and_source: HashMap<&String, Vec<String>> = HashMap::new();

if project.skip_file(project_file) {
return None;
}

let relative_path = project.relative_path(&project_file.path);

for owner_matcher in &owner_matchers {
Expand Down
8 changes: 1 addition & 7 deletions src/project.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,6 @@ pub struct Project {
pub packages: Vec<Package>,
pub vendored_gems: Vec<VendoredGem>,
pub teams: Vec<Team>,
pub unowned_globs: Vec<String>,
pub codeowners_file: String,
}

Expand DownExpand Up@@ -192,7 +191,7 @@ impl Project {
})
}

if matches_globs(&relative_path, &config.owned_globs) {
if matches_globs(&relative_path, &config.owned_globs) && !matches_globs(&relative_path, &config.unowned_globs) {
owned_file_paths.push(absolute_path)
}
}
Expand All@@ -219,7 +218,6 @@ impl Project {
vendored_gems,
teams,
packages,
unowned_globs: config.unowned_globs.clone(),
codeowners_file,
})
}
Expand DownExpand Up@@ -249,10 +247,6 @@ impl Project {

result
}

pub fn skip_file(&self, file: &ProjectFile) -> bool {
matches_globs(self.relative_path(&file.path), &self.unowned_globs)
}
}

#[instrument(level = "debug", skip_all)]
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/valid_project/.github/CODEOWNERS
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,4 +26,4 @@
/config/teams/payroll.yml @PayrollTeam

# Team owned gems
/gems/payroll_calculator @PayrollTeam
/gems/payroll_calculator/**/** @PayrollTeam