Skip to content

Commit 4d3cf0b

Browse files
committed
removing unused for-file code
1 parent ae6332e commit 4d3cf0b

File tree

5 files changed

+13
-267
lines changed

5 files changed

+13
-267
lines changed

src/bin/compare_for_file.rs

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

src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn cli() -> Result<RunResult, RunnerError> {
109109
Command::Validate => runner::validate(&run_config, vec![]),
110110
Command::Generate { skip_stage } => runner::generate(&run_config, !skip_stage),
111111
Command::GenerateAndValidate { skip_stage } => runner::generate_and_validate(&run_config, vec![], !skip_stage),
112-
Command::ForFile { name, fast } => runner::for_file(&run_config, &name, fast),
112+
Command::ForFile { name, fast: _ } => runner::for_file(&run_config, &name),
113113
Command::ForTeam { name } => runner::for_team(&run_config, &name),
114114
Command::DeleteCache => runner::delete_cache(&run_config),
115115
};

src/runner.rs

Lines changed: 2 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,8 @@ pub struct Runner {
3636
cache: Cache,
3737
}
3838

39-
pub fn for_file(run_config: &RunConfig, file_path: &str, fast: bool) -> RunResult {
40-
if fast {
41-
for_file_from_codeowners(run_config, file_path)
42-
} else {
43-
//run_with_runner(run_config, |runner| runner.for_file(file_path))
44-
for_file_optimized(run_config, file_path)
45-
}
46-
}
47-
48-
fn for_file_from_codeowners(run_config: &RunConfig, file_path: &str) -> RunResult {
49-
match team_for_file_from_codeowners(run_config, file_path) {
50-
Ok(Some(team)) => {
51-
let relative_team_yml_path = team.path.strip_prefix(&run_config.project_root).unwrap_or(&team.path);
52-
53-
RunResult {
54-
info_messages: vec![
55-
format!("Team: {}", team.name),
56-
format!("Team YML: {}", relative_team_yml_path.display()),
57-
],
58-
..Default::default()
59-
}
60-
}
61-
Ok(None) => RunResult {
62-
info_messages: vec!["Team: Unowned".to_string(), "Team YML:".to_string()],
63-
..Default::default()
64-
},
65-
Err(err) => RunResult {
66-
io_errors: vec![err.to_string()],
67-
..Default::default()
68-
},
69-
}
39+
pub fn for_file(run_config: &RunConfig, file_path: &str) -> RunResult {
40+
for_file_optimized(run_config, file_path)
7041
}
7142

7243
pub fn team_for_file_from_codeowners(run_config: &RunConfig, file_path: &str) -> Result<Option<Team>, Error> {
@@ -289,41 +260,6 @@ impl Runner {
289260
.output();
290261
}
291262

292-
// TODO: remove this once we've verified the fast path is working
293-
#[allow(dead_code)]
294-
pub fn for_file(&self, file_path: &str) -> RunResult {
295-
let relative_file_path = Path::new(file_path)
296-
.strip_prefix(&self.run_config.project_root)
297-
.unwrap_or(Path::new(file_path));
298-
let file_owners = match self.ownership.for_file(relative_file_path) {
299-
Ok(file_owners) => file_owners,
300-
Err(err) => {
301-
return RunResult {
302-
io_errors: vec![err.to_string()],
303-
..Default::default()
304-
};
305-
}
306-
};
307-
let info_messages: Vec<String> = match file_owners.len() {
308-
0 => vec![format!("{}", FileOwner::default())],
309-
1 => vec![format!("{}", file_owners[0])],
310-
_ => {
311-
let mut error_messages = vec!["Error: file is owned by multiple teams!".to_string()];
312-
for file_owner in file_owners {
313-
error_messages.push(format!("\n{}", file_owner));
314-
}
315-
return RunResult {
316-
validation_errors: error_messages,
317-
..Default::default()
318-
};
319-
}
320-
};
321-
RunResult {
322-
info_messages,
323-
..Default::default()
324-
}
325-
}
326-
327263
pub fn for_team(&self, team_name: &str) -> RunResult {
328264
let mut info_messages = vec![];
329265
let mut io_errors = vec![];

tests/invalid_project_test.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,24 +61,6 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
6161
Ok(())
6262
}
6363

64-
#[test]
65-
fn test_fast_for_file() -> Result<(), Box<dyn Error>> {
66-
Command::cargo_bin("codeowners")?
67-
.arg("--project-root")
68-
.arg("tests/fixtures/invalid_project")
69-
.arg("--no-cache")
70-
.arg("for-file")
71-
.arg("--fast")
72-
.arg("ruby/app/models/blockchain.rb")
73-
.assert()
74-
.success()
75-
.stdout(predicate::eq(indoc! {"
76-
Team: Unowned
77-
Team YML:
78-
"}));
79-
Ok(())
80-
}
81-
8264
#[test]
8365
fn test_for_file_multiple_owners() -> Result<(), Box<dyn Error>> {
8466
Command::cargo_bin("codeowners")?

tests/valid_project_test.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ fn test_fast_for_file() -> Result<(), Box<dyn Error>> {
8686
.arg("tests/fixtures/valid_project")
8787
.arg("--no-cache")
8888
.arg("for-file")
89-
.arg("--fast")
9089
.arg("ruby/app/models/payroll.rb")
9190
.assert()
9291
.success()
9392
.stdout(predicate::eq(indoc! {"
9493
Team: Payroll
94+
Github Team: @PayrollTeam
9595
Team YML: config/teams/payroll.yml
96+
Description:
97+
- Owner annotation at the top of the file
9698
"}));
9799
Ok(())
98100
}
@@ -127,13 +129,15 @@ fn test_fast_for_file_full_path() -> Result<(), Box<dyn Error>> {
127129
.arg(project_root)
128130
.arg("--no-cache")
129131
.arg("for-file")
130-
.arg("--fast")
131132
.arg(for_file_absolute_path.to_str().unwrap())
132133
.assert()
133134
.success()
134135
.stdout(predicate::eq(indoc! {"
135136
Team: Payroll
137+
Github Team: @PayrollTeam
136138
Team YML: config/teams/payroll.yml
139+
Description:
140+
- Owner annotation at the top of the file
137141
"}));
138142
Ok(())
139143
}
@@ -186,13 +190,16 @@ fn test_fast_for_file_same_team_multiple_ownerships() -> Result<(), Box<dyn Erro
186190
.arg("tests/fixtures/valid_project")
187191
.arg("--no-cache")
188192
.arg("for-file")
189-
.arg("--fast")
190193
.arg("javascript/packages/PayrollFlow/index.tsx")
191194
.assert()
192195
.success()
193196
.stdout(predicate::eq(indoc! {"
194197
Team: Payroll
198+
Github Team: @PayrollTeam
195199
Team YML: config/teams/payroll.yml
200+
Description:
201+
- Owner annotation at the top of the file
202+
- Owner defined in `javascript/packages/PayrollFlow/package.json` with implicity owned glob: `javascript/packages/PayrollFlow/**/**`
196203
"}));
197204
Ok(())
198205
}

0 commit comments

Comments
 (0)