Skip to content

Commit 23ba0f5

Browse files
committed
from codeowners only
1 parent 988f272 commit 23ba0f5

File tree

4 files changed

+36
-55
lines changed

4 files changed

+36
-55
lines changed

ai-prompts/overrides.md

Lines changed: 0 additions & 48 deletions
This file was deleted.

src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ enum Command {
1616
default_value = "false",
1717
help = "Find the owner from the CODEOWNERS file and just return the team name and yml path"
1818
)]
19-
fast: bool,
19+
from_codeowners: bool,
2020
name: String,
2121
},
2222

@@ -113,7 +113,7 @@ pub fn cli() -> Result<RunResult, RunnerError> {
113113
Command::Validate => runner::validate(&run_config, vec![]),
114114
Command::Generate { skip_stage } => runner::generate(&run_config, !skip_stage),
115115
Command::GenerateAndValidate { skip_stage } => runner::generate_and_validate(&run_config, vec![], !skip_stage),
116-
Command::ForFile { name, fast: _ } => runner::for_file(&run_config, &name),
116+
Command::ForFile { name, from_codeowners } => runner::for_file(&run_config, &name, from_codeowners),
117117
Command::ForTeam { name } => runner::for_team(&run_config, &name),
118118
Command::DeleteCache => runner::delete_cache(&run_config),
119119
Command::VerifyCompareForFile => runner::verify_compare_for_file(&run_config),

src/runner.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,37 @@ pub struct Runner {
3636
cache: Cache,
3737
}
3838

39-
pub fn for_file(run_config: &RunConfig, file_path: &str) -> RunResult {
39+
pub fn for_file(run_config: &RunConfig, file_path: &str, from_codeowners: bool) -> RunResult {
40+
if from_codeowners {
41+
return for_file_codeowners_only(run_config, file_path);
42+
}
4043
for_file_optimized(run_config, file_path)
4144
}
4245

46+
fn for_file_codeowners_only(run_config: &RunConfig, file_path: &str) -> RunResult {
47+
match team_for_file_from_codeowners(run_config, file_path) {
48+
Ok(Some(team)) => {
49+
let relative_team_path = team
50+
.path
51+
.strip_prefix(&run_config.project_root)
52+
.unwrap_or(team.path.as_path())
53+
.to_string_lossy()
54+
.to_string();
55+
RunResult {
56+
info_messages: vec![format!(
57+
"Team: {}\nGithub Team: {}\nTeam YML: {}\nDescription:\n- Owner inferred from codeowners file",
58+
team.name, team.github_team, relative_team_path
59+
)],
60+
..Default::default()
61+
}
62+
}
63+
Ok(None) => RunResult::default(),
64+
Err(err) => RunResult {
65+
io_errors: vec![err.to_string()],
66+
..Default::default()
67+
},
68+
}
69+
}
4370
pub fn team_for_file_from_codeowners(run_config: &RunConfig, file_path: &str) -> Result<Option<Team>, Error> {
4471
let config = config_from_path(&run_config.config_path)?;
4572
let relative_file_path = Path::new(file_path)

tests/verify_compare_for_file_mismatch_test.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ fn test_verify_compare_for_file_reports_team_mismatch() -> Result<(), Box<dyn Er
3131
.arg("verify-compare-for-file")
3232
.assert()
3333
.failure()
34-
.stdout(predicate::str::contains(indoc! {"- ruby/app/models/payroll.rb: CODEOWNERS=Payments fast=Payroll"}));
34+
.stdout(predicate::str::contains(
35+
indoc! {"- ruby/app/models/payroll.rb: CODEOWNERS=Payments fast=Payroll"},
36+
));
3537

3638
Ok(())
3739
}
@@ -60,9 +62,9 @@ fn test_verify_compare_for_file_reports_unowned_mismatch() -> Result<(), Box<dyn
6062
.arg("verify-compare-for-file")
6163
.assert()
6264
.failure()
63-
.stdout(predicate::str::contains("- ruby/app/models/bank_account.rb: CODEOWNERS=Unowned fast=Payments"));
65+
.stdout(predicate::str::contains(
66+
"- ruby/app/models/bank_account.rb: CODEOWNERS=Unowned fast=Payments",
67+
));
6468

6569
Ok(())
6670
}
67-
68-

0 commit comments

Comments
 (0)