Skip to content

Commit 134f7ef

Browse files
committed
stubbing out teams_for_files_from_codeowners
1 parent 9cee8f0 commit 134f7ef

File tree

3 files changed

+264
-118
lines changed

3 files changed

+264
-118
lines changed

src/ownership.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use std::{
99
};
1010
use tracing::{info, instrument};
1111

12-
pub(crate) mod codeowners_file_parser;
13-
pub(crate) mod codeowners_query;
1412
mod file_generator;
1513
mod file_owner_finder;
16-
pub mod file_owner_resolver;
14+
pub mod for_file_fast;
1715
pub(crate) mod mapper;
16+
pub(crate) mod codeowners_file_parser;
1817
mod validator;
1918

2019
use crate::{
@@ -25,9 +24,9 @@ use crate::{
2524
pub use validator::Errors as ValidatorErrors;
2625

2726
use self::{
28-
codeowners_file_parser::parse_for_team,
2927
file_generator::FileGenerator,
3028
mapper::{JavascriptPackageMapper, Mapper, RubyPackageMapper, TeamFileMapper, TeamGemMapper, TeamGlobMapper, TeamYmlMapper},
29+
codeowners_file_parser::parse_for_team,
3130
validator::Validator,
3231
};
3332

src/ownership/codeowners_file_parser.rs

Lines changed: 25 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use crate::{
44
};
55
use fast_glob::glob_match;
66
use memoize::memoize;
7-
use rayon::prelude::*;
87
use regex::Regex;
98
use std::{
109
collections::HashMap,
@@ -23,57 +22,33 @@ pub struct Parser {
2322
}
2423

2524
impl Parser {
26-
pub fn teams_from_files_paths(&self, file_paths: &[PathBuf]) -> Result<HashMap<String, Option<Team>>, Box<dyn Error>> {
27-
let file_inputs: Vec<(String, String)> = file_paths
28-
.iter()
29-
.map(|path| {
30-
let file_path_str = path
31-
.to_str()
32-
.ok_or(IoError::new(std::io::ErrorKind::InvalidInput, "Invalid file path"))?;
33-
let original = file_path_str.to_string();
34-
let prefixed = if file_path_str.starts_with('/') {
35-
original.clone()
36-
} else {
37-
format!("/{}", file_path_str)
38-
};
39-
Ok((original, prefixed))
40-
})
41-
.collect::<Result<Vec<_>, IoError>>()?;
42-
43-
if file_inputs.is_empty() {
44-
return Ok(HashMap::new());
45-
}
46-
47-
let codeowners_entries: Vec<(String, String)> =
48-
build_codeowners_lines_in_priority(self.codeowners_file_path.to_string_lossy().into_owned())
49-
.iter()
50-
.map(|line| {
51-
line.split_once(' ')
52-
.map(|(glob, team_name)| (glob.to_string(), team_name.to_string()))
53-
.ok_or_else(|| IoError::new(std::io::ErrorKind::InvalidInput, "Invalid line"))
54-
})
55-
.collect::<Result<_, IoError>>()
56-
.map_err(|e| Box::new(e) as Box<dyn Error>)?;
57-
58-
let teams_by_name = teams_by_github_team_name(self.absolute_team_files_globs());
59-
60-
let result: HashMap<String, Option<Team>> = file_inputs
61-
.par_iter()
62-
.map(|(key, prefixed)| {
63-
let team = codeowners_entries
64-
.iter()
65-
.find(|(glob, _)| glob_match(glob, prefixed))
66-
.and_then(|(_, team_name)| teams_by_name.get(team_name).cloned());
67-
(key.clone(), team)
68-
})
69-
.collect();
70-
71-
Ok(result)
25+
pub fn teams_from_files_paths(&self, file_paths: &[PathBuf]) -> Result<HashMap<String, Team>, Box<dyn Error>> {
26+
todo!()
7227
}
73-
28+
7429
pub fn team_from_file_path(&self, file_path: &Path) -> Result<Option<Team>, Box<dyn Error>> {
75-
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().flatten())
30+
let file_path_str = file_path
31+
.to_str()
32+
.ok_or(IoError::new(std::io::ErrorKind::InvalidInput, "Invalid file path"))?;
33+
let slash_prefixed = if file_path_str.starts_with("/") {
34+
file_path_str.to_string()
35+
} else {
36+
format!("/{}", file_path_str)
37+
};
38+
39+
let codeowners_lines_in_priorty = build_codeowners_lines_in_priority(self.codeowners_file_path.to_string_lossy().into_owned());
40+
for line in codeowners_lines_in_priorty {
41+
let (glob, team_name) = line
42+
.split_once(' ')
43+
.ok_or(IoError::new(std::io::ErrorKind::InvalidInput, "Invalid line"))?;
44+
if glob_match(glob, &slash_prefixed) {
45+
let tbn = teams_by_github_team_name(self.absolute_team_files_globs());
46+
let team: Option<Team> = tbn.get(team_name.to_string().as_str()).cloned();
47+
return Ok(team);
48+
}
49+
}
50+
51+
Ok(None)
7752
}
7853

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

0 commit comments

Comments
 (0)