-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathconfig.rs
More file actions
125 lines (103 loc) · 3.31 KB
/
config.rs
File metadata and controls
125 lines (103 loc) · 3.31 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
pub struct Config {
pub owned_globs: Vec<String>,
#[serde(default = "ruby_package_paths")]
pub ruby_package_paths: Vec<String>,
#[serde(alias = "js_package_paths", default = "javascript_package_paths")]
pub javascript_package_paths: Vec<String>,
#[serde(default = "team_file_glob")]
pub team_file_glob: Vec<String>,
#[serde(default = "unowned_globs")]
pub unowned_globs: Vec<String>,
#[serde(alias = "unbuilt_gems_path", default = "vendored_gems_path")]
pub vendored_gems_path: String,
#[serde(default = "default_cache_directory")]
pub cache_directory: String,
#[serde(default = "default_ignore_dirs")]
pub ignore_dirs: Vec<String>,
#[serde(default = "default_skip_untracked_files")]
pub skip_untracked_files: bool,
}
#[allow(dead_code)]
#[derive(Deserialize, Debug)]
pub struct RubyPackageConfig {
#[serde(alias = "pack_paths")]
pub ruby_package_paths: Vec<String>,
}
fn ruby_package_paths() -> Vec<String> {
vec!["packs/**/*".to_owned(), "components/**".to_owned()]
}
fn team_file_glob() -> Vec<String> {
vec!["config/teams/**/*.yml".to_owned()]
}
fn default_cache_directory() -> String {
String::from("tmp/cache/codeowners")
}
fn javascript_package_paths() -> Vec<String> {
vec!["frontend/**/*".to_owned()]
}
fn unowned_globs() -> Vec<String> {
vec![
"frontend/**/node_modules/**/*".to_owned(),
"frontend/**/__generated__/**/*".to_owned(),
]
}
fn vendored_gems_path() -> String {
"vendored/".to_string()
}
fn default_skip_untracked_files() -> bool {
true
}
fn default_ignore_dirs() -> Vec<String> {
vec![
".cursor".to_owned(),
".git".to_owned(),
".idea".to_owned(),
".vscode".to_owned(),
".yarn".to_owned(),
"ar_doc".to_owned(),
"db".to_owned(),
"helm".to_owned(),
"log".to_owned(),
"node_modules".to_owned(),
"sorbet".to_owned(),
"tmp".to_owned(),
]
}
#[cfg(test)]
mod tests {
use std::{
error::Error,
fs::{self, File},
};
use indoc::indoc;
use tempfile::tempdir;
use super::*;
#[test]
fn test_parse_config() -> Result<(), Box<dyn Error>> {
let temp_dir = tempdir()?;
let config_path = temp_dir.path().join("config.yml");
let config_str = indoc! {"
---
owned_globs:
- \"{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml}\"
"};
fs::write(&config_path, config_str)?;
let config_file = File::open(&config_path)?;
let config: Config = serde_yaml::from_reader(config_file)?;
assert_eq!(
config.owned_globs,
vec!["{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml}"]
);
assert_eq!(config.ruby_package_paths, vec!["packs/**/*", "components/**"]);
assert_eq!(config.javascript_package_paths, vec!["frontend/**/*"]);
assert_eq!(config.team_file_glob, vec!["config/teams/**/*.yml"]);
assert_eq!(
config.unowned_globs,
vec!["frontend/**/node_modules/**/*", "frontend/**/__generated__/**/*"]
);
assert_eq!(config.vendored_gems_path, "vendored/");
Ok(())
}
}