Skip to content

Commit acd49c7

Browse files
committed
Add support for custom executable_name in config
1 parent 1c0fa31 commit acd49c7

File tree

9 files changed

+89
-1
lines changed

9 files changed

+89
-1
lines changed

src/config.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,40 @@ mod tests {
128128
vec!["frontend/**/node_modules/**/*", "frontend/**/__generated__/**/*"]
129129
);
130130
assert_eq!(config.vendored_gems_path, "vendored/");
131+
assert_eq!(config.executable_name, "codeowners");
132+
Ok(())
133+
}
134+
135+
#[test]
136+
fn test_parse_config_with_custom_executable_name() -> Result<(), Box<dyn Error>> {
137+
let temp_dir = tempdir()?;
138+
let config_path = temp_dir.path().join("config.yml");
139+
let config_str = indoc! {"
140+
---
141+
owned_globs:
142+
- \"**/*.rb\"
143+
executable_name: my-custom-codeowners
144+
"};
145+
fs::write(&config_path, config_str)?;
146+
let config_file = File::open(&config_path)?;
147+
let config: Config = serde_yaml::from_reader(config_file)?;
148+
assert_eq!(config.executable_name, "my-custom-codeowners");
149+
Ok(())
150+
}
151+
152+
#[test]
153+
fn test_executable_name_defaults_when_not_specified() -> Result<(), Box<dyn Error>> {
154+
let temp_dir = tempdir()?;
155+
let config_path = temp_dir.path().join("config.yml");
156+
let config_str = indoc! {"
157+
---
158+
owned_globs:
159+
- \"**/*.rb\"
160+
"};
161+
fs::write(&config_path, config_str)?;
162+
let config_file = File::open(&config_path)?;
163+
let config: Config = serde_yaml::from_reader(config_file)?;
164+
assert_eq!(config.executable_name, "codeowners");
131165
Ok(())
132166
}
133167
}

src/ownership/file_owner_resolver.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ mod tests {
293293
vendored_gems_path: vendored_path.to_string(),
294294
cache_directory: "tmp/cache/codeowners".to_string(),
295295
ignore_dirs: vec![],
296+
executable_name: "codeowners".to_string(),
296297
}
297298
}
298299

src/ownership/validator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl Error {
169169
Error::FileWithoutOwner { path: _ } => "Some files are missing ownership".to_owned(),
170170
Error::FileWithMultipleOwners { path: _, owners: _ } => "Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways".to_owned(),
171171
Error::CodeownershipFileIsStale { executable_name } => {
172-
format!("CODEOWNERS out of date. Run `{} generate` to update the CODEOWNERS file", executable_name.to_string())
172+
format!("CODEOWNERS out of date. Run `{} generate` to update the CODEOWNERS file", executable_name)
173173
}
174174
Error::InvalidTeam { name: _, path: _ } => "Found invalid team annotations".to_owned(),
175175
}

src/project.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ mod tests {
220220
codeowners_file_path: PathBuf::from(".github/CODEOWNERS"),
221221
directory_codeowner_files: vec![],
222222
teams_by_name: HashMap::new(),
223+
executable_name: "codeowners".to_string(),
223224
};
224225

225226
let map = project.vendored_gem_by_name();
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use predicates::prelude::*;
2+
use std::error::Error;
3+
4+
mod common;
5+
use common::OutputStream;
6+
use common::run_codeowners;
7+
8+
#[test]
9+
fn test_validate_uses_custom_executable_name() -> Result<(), Box<dyn Error>> {
10+
run_codeowners(
11+
"custom_executable_name",
12+
&["validate"],
13+
false,
14+
OutputStream::Stdout,
15+
predicate::str::contains("CODEOWNERS out of date. Run `my-custom-tool generate` to update the CODEOWNERS file"),
16+
)?;
17+
Ok(())
18+
}
19+
20+
#[test]
21+
fn test_validate_default_executable_name() -> Result<(), Box<dyn Error>> {
22+
// This tests the invalid_project which doesn't specify executable_name
23+
// and should use the default "codeowners"
24+
run_codeowners(
25+
"invalid_project",
26+
&["validate"],
27+
false,
28+
OutputStream::Stdout,
29+
predicate::str::contains("CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file"),
30+
)?;
31+
Ok(())
32+
}
33+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This is a stale CODEOWNERS file - it's intentionally wrong to trigger the error
2+
ruby/app/payments/bar.rb @PaymentTeam
3+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
owned_globs:
2+
- "**/*.rb"
3+
team_file_glob:
4+
- config/teams/**/*.yml
5+
executable_name: my-custom-tool
6+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Payments
2+
github:
3+
team: "@PaymentTeam"
4+
owned_globs:
5+
- ruby/app/payments/**
6+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# A file owned by Payments
2+
class Foo
3+
end
4+

0 commit comments

Comments
 (0)