Skip to content

Commit 00c88d6

Browse files
committed
bumping crates
1 parent 21a3d29 commit 00c88d6

File tree

2 files changed

+40
-14
lines changed

2 files changed

+40
-14
lines changed

src/ownership/codeowners_file_parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Parser {
2323
}
2424

2525
impl Parser {
26-
pub fn teams_from_files_paths(&self, file_paths: &[PathBuf]) -> Result<HashMap<String, Team>, Box<dyn Error>> {
26+
pub fn teams_from_files_paths(&self, file_paths: &[PathBuf]) -> Result<HashMap<String, Option<Team>>, Box<dyn Error>> {
2727
let file_inputs: Vec<(String, String)> = file_paths
2828
.iter()
2929
.map(|path| {
@@ -57,14 +57,14 @@ impl Parser {
5757

5858
let teams_by_name = teams_by_github_team_name(self.absolute_team_files_globs());
5959

60-
let result: HashMap<String, Team> = file_inputs
60+
let result: HashMap<String, Option<Team>> = file_inputs
6161
.par_iter()
62-
.filter_map(|(key, prefixed)| {
63-
codeowners_entries
62+
.map(|(key, prefixed)| {
63+
let team = codeowners_entries
6464
.iter()
6565
.find(|(glob, _)| glob_match(glob, prefixed))
66-
.and_then(|(_, team_name)| teams_by_name.get(team_name))
67-
.map(|team| (key.clone(), team.clone()))
66+
.and_then(|(_, team_name)| teams_by_name.get(team_name).cloned());
67+
(key.clone(), team)
6868
})
6969
.collect();
7070

@@ -73,7 +73,7 @@ impl Parser {
7373

7474
pub fn team_from_file_path(&self, file_path: &Path) -> Result<Option<Team>, Box<dyn Error>> {
7575
let teams = self.teams_from_files_paths(&[file_path.to_path_buf()])?;
76-
Ok(teams.get(file_path.to_string_lossy().into_owned().as_str()).cloned())
76+
Ok(teams.get(file_path.to_string_lossy().into_owned().as_str()).cloned().flatten())
7777
}
7878

7979
fn absolute_team_files_globs(&self) -> Vec<String> {

src/runner.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn for_file_codeowners_only(run_config: &RunConfig, file_path: &str) -> RunResul
283283
}
284284

285285
// For an array of file paths, return a map of file path to its owning team
286-
pub fn teams_for_files_from_codeowners(run_config: &RunConfig, file_paths: &[String]) -> Result<HashMap<String, Team>, Error> {
286+
pub fn teams_for_files_from_codeowners(run_config: &RunConfig, file_paths: &[String]) -> Result<HashMap<String, Option<Team>>, Error> {
287287
let relative_file_paths: Vec<PathBuf> = file_paths
288288
.iter()
289289
.map(|path| Path::new(path).strip_prefix(&run_config.project_root).unwrap_or(Path::new(path)))
@@ -435,17 +435,43 @@ mod tests {
435435
};
436436
let teams =
437437
teams_for_files_from_codeowners(&run_config, &file_paths.iter().map(|s| s.to_string()).collect::<Vec<String>>()).unwrap();
438-
assert_eq!(teams.len(), 3);
438+
assert_eq!(teams.len(), 5);
439439
assert_eq!(
440-
teams.get("javascript/packages/items/item.ts").map(|t| t.name.as_str()),
440+
teams
441+
.get("javascript/packages/items/item.ts")
442+
.unwrap()
443+
.as_ref()
444+
.map(|t| t.name.as_str()),
441445
Some("Payroll")
442446
);
443-
assert_eq!(teams.get("config/teams/payroll.yml").map(|t| t.name.as_str()), Some("Payroll"));
444447
assert_eq!(
445-
teams.get("ruby/app/models/bank_account.rb").map(|t| t.name.as_str()),
448+
teams.get("config/teams/payroll.yml").unwrap().as_ref().map(|t| t.name.as_str()),
449+
Some("Payroll")
450+
);
451+
assert_eq!(
452+
teams
453+
.get("ruby/app/models/bank_account.rb")
454+
.unwrap()
455+
.as_ref()
456+
.map(|t| t.name.as_str()),
446457
Some("Payments")
447458
);
448-
assert_eq!(teams.get("made/up/file.rb").map(|t| t.name.as_str()), None);
449-
assert_eq!(teams.get("ruby/ignored_files/git_ignored.rb").map(|t| t.name.as_str()), None);
459+
assert_eq!(teams.get("made/up/file.rb").unwrap().as_ref().map(|t| t.name.as_str()), None);
460+
assert_eq!(
461+
teams
462+
.get("ruby/ignored_files/git_ignored.rb")
463+
.unwrap()
464+
.as_ref()
465+
.map(|t| t.name.as_str()),
466+
None
467+
);
468+
assert_eq!(
469+
teams
470+
.get("ruby/ignored_files/git_ignored.rb")
471+
.unwrap()
472+
.as_ref()
473+
.map(|t| t.name.as_str()),
474+
None
475+
);
450476
}
451477
}

0 commit comments

Comments
 (0)