Skip to content

Commit 1b87d0f

Browse files
committed
config file as yml
1 parent e49fc63 commit 1b87d0f

File tree

6 files changed

+42
-14
lines changed

6 files changed

+42
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codeowners"
3-
version = "0.2.12"
3+
version = "0.2.13"
44
edition = "2024"
55

66
[profile.release]

src/config.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ pub struct Config {
2525
#[serde(default = "default_ignore_dirs")]
2626
pub ignore_dirs: Vec<String>,
2727

28-
#[serde(default = "default_skip_untracked_files_config_path")]
29-
pub skip_untracked_files_config_path: String,
28+
#[serde(default = "default_codeowners_override_config_file_path")]
29+
pub codeowners_override_config_file_path: String,
3030
}
3131

3232
#[allow(dead_code)]
@@ -63,8 +63,8 @@ fn vendored_gems_path() -> String {
6363
"vendored/".to_string()
6464
}
6565

66-
fn default_skip_untracked_files_config_path() -> String {
67-
".codeowners-skip-untracked-files".to_string()
66+
fn default_codeowners_override_config_file_path() -> String {
67+
".codeowners.yml".to_string()
6868
}
6969

7070
fn default_ignore_dirs() -> Vec<String> {

src/ownership/for_file_fast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ mod tests {
303303
vendored_gems_path: vendored_path.to_string(),
304304
cache_directory: "tmp/cache/codeowners".to_string(),
305305
ignore_dirs: vec![],
306-
skip_untracked_files_config_path: ".codeowners-skip-untracked-files".to_string(),
306+
codeowners_override_config_file_path: ".codeowners.yml".to_string(),
307307
}
308308
}
309309

src/project_builder.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use error_stack::{Report, Result, ResultExt};
88
use fast_glob::glob_match;
99
use ignore::{DirEntry, WalkBuilder, WalkParallel, WalkState};
1010
use rayon::iter::{IntoParallelIterator, ParallelIterator};
11+
use serde::Deserialize;
1112
use tracing::{instrument, warn};
1213

1314
use crate::{
@@ -61,7 +62,7 @@ impl<'a> ProjectBuilder<'a> {
6162
// Prune traversal early: skip heavy and irrelevant directories
6263
let ignore_dirs = self.config.ignore_dirs.clone();
6364
let base_path = self.base_path.clone();
64-
let untracked_files = if skip_untracked_files_config_path_exists(&self.base_path, &self.config.skip_untracked_files_config_path) {
65+
let untracked_files = if should_skip_untracked_files(&self.base_path, &self.config.codeowners_override_config_file_path) {
6566
files::untracked_files(&base_path).unwrap_or_default()
6667
} else {
6768
vec![]
@@ -297,10 +298,27 @@ fn matches_globs(path: &Path, globs: &[String]) -> bool {
297298
}
298299
}
299300

300-
// If skip_untracked_files_config_path exists, we skip untracked files. We don't do this be default because it's slow.
301-
fn skip_untracked_files_config_path_exists(base_path: &Path, skip_untracked_files_config_path: &str) -> bool {
302-
let path = base_path.join(skip_untracked_files_config_path);
303-
path.exists()
301+
fn should_skip_untracked_files(base_path: &Path, codeowners_override_config_file_path: &str) -> bool {
302+
let path = base_path.join(codeowners_override_config_file_path);
303+
if !path.exists() {
304+
return false;
305+
}
306+
if let Ok(file) = File::open(path) {
307+
#[derive(Deserialize)]
308+
struct OverrideConfig {
309+
#[serde(default)]
310+
skip_untracked_files: bool,
311+
}
312+
313+
let config: OverrideConfig = match serde_yaml::from_reader(file) {
314+
Ok(cfg) => cfg,
315+
Err(_) => return false,
316+
};
317+
318+
return config.skip_untracked_files;
319+
}
320+
321+
false
304322
}
305323

306324
fn ruby_package_owner(path: &Path) -> Result<Option<String>, Error> {

tests/untracked_files_test.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fn test_skip_untracked_files() -> Result<(), Box<dyn Error>> {
2121
.assert()
2222
.failure();
2323

24-
let skip_untracked_files_config_path = project_root.join(".codeowners-skip-untracked-files");
25-
fs::write(&skip_untracked_files_config_path, "true")?;
24+
let skip_untracked_files_config_path = project_root.join(".codeowners.yml");
25+
fs::write(&skip_untracked_files_config_path, "skip_untracked_files: true")?;
2626

2727
// should succeed if skip_untracked_false is false
2828
Command::cargo_bin("codeowners")?
@@ -33,5 +33,15 @@ fn test_skip_untracked_files() -> Result<(), Box<dyn Error>> {
3333
.assert()
3434
.success();
3535

36+
// should fail if skip_untracked_false is false
37+
fs::write(&skip_untracked_files_config_path, "skip_untracked_files: false")?;
38+
Command::cargo_bin("codeowners")?
39+
.arg("--project-root")
40+
.arg(project_root)
41+
.arg("--no-cache")
42+
.arg("gv")
43+
.assert()
44+
.failure();
45+
3646
Ok(())
3747
}

0 commit comments

Comments
 (0)