-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcodeowners_query.rs
More file actions
53 lines (46 loc) · 1.59 KB
/
codeowners_query.rs
File metadata and controls
53 lines (46 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use crate::ownership::codeowners_file_parser::Parser;
use crate::project::Team;
pub(crate) fn team_for_file_from_codeowners(
project_root: &Path,
codeowners_file_path: &Path,
team_file_globs: &[String],
file_path: &Path,
) -> Result<Option<Team>, String> {
let relative_file_path = if file_path.is_absolute() {
crate::path_utils::relative_to_buf(project_root, file_path)
} else {
PathBuf::from(file_path)
};
let parser = Parser {
codeowners_file_path: codeowners_file_path.to_path_buf(),
project_root: project_root.to_path_buf(),
team_file_globs: team_file_globs.to_vec(),
};
parser.team_from_file_path(&relative_file_path).map_err(|e| e.to_string())
}
pub(crate) fn teams_for_files_from_codeowners(
project_root: &Path,
codeowners_file_path: &Path,
team_file_globs: &[String],
file_paths: &[String],
) -> Result<HashMap<String, Option<Team>>, String> {
let relative_file_paths: Vec<PathBuf> = file_paths
.iter()
.map(Path::new)
.map(|path| {
if path.is_absolute() {
crate::path_utils::relative_to_buf(project_root, path)
} else {
path.to_path_buf()
}
})
.collect();
let parser = Parser {
codeowners_file_path: codeowners_file_path.to_path_buf(),
project_root: project_root.to_path_buf(),
team_file_globs: team_file_globs.to_vec(),
};
parser.teams_from_files_paths(&relative_file_paths).map_err(|e| e.to_string())
}