Skip to content

Commit f947d86

Browse files
committed
stubbing out teams_for_files_from_codeowners
1 parent 55832fc commit f947d86

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

src/ownership.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ mod file_generator;
1313
mod file_owner_finder;
1414
pub mod for_file_fast;
1515
pub(crate) mod mapper;
16-
pub(crate) mod parser;
16+
pub(crate) mod codeowners_file_parser;
1717
mod validator;
1818

1919
use crate::{
@@ -26,7 +26,7 @@ pub use validator::Errors as ValidatorErrors;
2626
use self::{
2727
file_generator::FileGenerator,
2828
mapper::{JavascriptPackageMapper, Mapper, RubyPackageMapper, TeamFileMapper, TeamGemMapper, TeamGlobMapper, TeamYmlMapper},
29-
parser::parse_for_team,
29+
codeowners_file_parser::parse_for_team,
3030
validator::Validator,
3131
};
3232

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ pub struct Parser {
2222
}
2323

2424
impl Parser {
25+
pub fn teams_from_files_paths(&self, file_paths: &[PathBuf]) -> Result<HashMap<String, Team>, Box<dyn Error>> {
26+
todo!()
27+
}
28+
2529
pub fn team_from_file_path(&self, file_path: &Path) -> Result<Option<Team>, Box<dyn Error>> {
2630
let file_path_str = file_path
2731
.to_str()

src/runner.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use core::fmt;
22
use std::{
3+
collections::HashMap,
34
fs::File,
45
path::{Path, PathBuf},
56
process::Command,
@@ -280,17 +281,36 @@ fn for_file_codeowners_only(run_config: &RunConfig, file_path: &str) -> RunResul
280281
},
281282
}
282283
}
283-
pub fn team_for_file_from_codeowners(run_config: &RunConfig, file_path: &str) -> Result<Option<Team>, Error> {
284+
285+
// 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> {
287+
let relative_file_paths: Vec<PathBuf> = file_paths
288+
.iter()
289+
.map(|path| Path::new(path).strip_prefix(&run_config.project_root).unwrap_or(Path::new(path)))
290+
.map(|path| path.to_path_buf())
291+
.collect();
292+
293+
let parser = build_codeowners_parser(run_config)?;
294+
Ok(parser
295+
.teams_from_files_paths(&relative_file_paths)
296+
.map_err(|e| Error::Io(e.to_string()))?)
297+
}
298+
299+
fn build_codeowners_parser(run_config: &RunConfig) -> Result<crate::ownership::codeowners_file_parser::Parser, Error> {
284300
let config = config_from_path(&run_config.config_path)?;
301+
Ok(crate::ownership::codeowners_file_parser::Parser {
302+
codeowners_file_path: run_config.codeowners_file_path.clone(),
303+
project_root: run_config.project_root.clone(),
304+
team_file_globs: config.team_file_glob.clone(),
305+
})
306+
}
307+
308+
pub fn team_for_file_from_codeowners(run_config: &RunConfig, file_path: &str) -> Result<Option<Team>, Error> {
285309
let relative_file_path = Path::new(file_path)
286310
.strip_prefix(&run_config.project_root)
287311
.unwrap_or(Path::new(file_path));
288312

289-
let parser = crate::ownership::parser::Parser {
290-
project_root: run_config.project_root.clone(),
291-
codeowners_file_path: run_config.codeowners_file_path.clone(),
292-
team_file_globs: config.team_file_glob.clone(),
293-
};
313+
let parser = build_codeowners_parser(run_config)?;
294314
Ok(parser
295315
.team_from_file_path(Path::new(relative_file_path))
296316
.map_err(|e| Error::Io(e.to_string()))?)

0 commit comments

Comments
 (0)