diff --git a/.gitignore b/.gitignore index 4932c6a..a83aeee 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .DS_Store /tmp +**/project-file-cache.json diff --git a/Cargo.lock b/Cargo.lock index 010d6e6..877c207 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,7 @@ checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" [[package]] name = "codeowners" -version = "0.2.9" +version = "0.2.10" dependencies = [ "assert_cmd", "clap", diff --git a/Cargo.toml b/Cargo.toml index 00aa843..f8df596 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "codeowners" -version = "0.2.9" +version = "0.2.10" edition = "2024" [profile.release] diff --git a/dev/run_benchmarks_for_gv.sh b/dev/run_benchmarks_for_gv.sh index 460f24c..1277351 100755 --- a/dev/run_benchmarks_for_gv.sh +++ b/dev/run_benchmarks_for_gv.sh @@ -9,5 +9,4 @@ echo "To run these benchmarks on your application, you can place this repo next hyperfine --warmup=2 --runs=3 --export-markdown tmp/codeowners_benchmarks_gv.md \ '../rubyatscale/codeowners-rs/target/release/codeowners gv' \ - 'bin/codeownership validate' \ - 'bin/codeowners-rs gv' \ No newline at end of file + 'bin/codeownership validate' \ No newline at end of file diff --git a/src/common_test.rs b/src/common_test.rs index 2dea43f..c4332b4 100644 --- a/src/common_test.rs +++ b/src/common_test.rs @@ -31,7 +31,7 @@ pub mod tests { const DEFAULT_CODE_OWNERSHIP_YML: &str = indoc! {" --- owned_globs: - - \"{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml}\" + - \"{app,components,config,frontend,lib,packs,spec,ruby}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml,erb}\" unowned_globs: - config/code_ownership.yml javascript_package_paths: @@ -248,7 +248,7 @@ pub mod tests { }, TestProjectFile { relative_path: "packs/jscomponents/comp-colon.ts".to_owned(), - content: "// @team: FooColon\n".to_owned(), + content: "// @team: Foo\n".to_owned(), }, TestProjectFile { relative_path: "packs/[admin]/comp.ts".to_owned(), @@ -259,8 +259,20 @@ pub mod tests { content: "# @team Bar\n".to_owned(), }, TestProjectFile { - relative_path: "packs/bar/comp-colon.rb".to_owned(), - content: "# @team: BarColon\n".to_owned(), + relative_path: "packs/bar/comp_colon.rb".to_owned(), + content: "# @team: Bar\n".to_owned(), + }, + TestProjectFile { + relative_path: "ruby/app/views/foos/edit.erb".to_owned(), + content: "<%# @team: Foo %>\n".to_owned(), + }, + TestProjectFile { + relative_path: "ruby/app/views/foos/show.html.erb".to_owned(), + content: "\n".to_owned(), + }, + TestProjectFile { + relative_path: "ruby/app/views/foos/_row.html.erb".to_owned(), + content: "\n".to_owned(), }, ], ); diff --git a/src/ownership/mapper/team_file_mapper.rs b/src/ownership/mapper/team_file_mapper.rs index f82d688..00518b7 100644 --- a/src/ownership/mapper/team_file_mapper.rs +++ b/src/ownership/mapper/team_file_mapper.rs @@ -99,6 +99,36 @@ mod tests { team_name: "Bar".to_owned(), disabled: false, }, + Entry { + path: "packs/bar/comp_colon.rb".to_owned(), + github_team: "@Bar".to_owned(), + team_name: "Bar".to_owned(), + disabled: false, + }, + Entry { + path: "packs/jscomponents/comp-colon.ts".to_owned(), + github_team: "@Foo".to_owned(), + team_name: "Foo".to_owned(), + disabled: false, + }, + Entry { + path: "ruby/app/views/foos/edit.erb".to_owned(), + github_team: "@Foo".to_owned(), + team_name: "Foo".to_owned(), + disabled: false, + }, + Entry { + path: "ruby/app/views/foos/show.html.erb".to_owned(), + github_team: "@Bar".to_owned(), + team_name: "Bar".to_owned(), + disabled: false, + }, + Entry { + path: "ruby/app/views/foos/_row.html.erb".to_owned(), + github_team: "@Bam".to_owned(), + team_name: "Bam".to_owned(), + disabled: false, + }, ], ); Ok(()) @@ -114,8 +144,11 @@ mod tests { (PathBuf::from("packs/[admin]/comp.ts"), "Bar".to_owned()), (PathBuf::from("packs/bar/comp.rb"), "Bar".to_owned()), (PathBuf::from("packs/jscomponents/comp.ts"), "Foo".to_owned()), - (PathBuf::from("packs/jscomponents/comp-colon.ts"), "FooColon".to_owned()), - (PathBuf::from("packs/bar/comp-colon.rb"), "BarColon".to_owned()), + (PathBuf::from("packs/jscomponents/comp-colon.ts"), "Foo".to_owned()), + (PathBuf::from("packs/bar/comp_colon.rb"), "Bar".to_owned()), + (PathBuf::from("ruby/app/views/foos/edit.erb"), "Foo".to_owned()), + (PathBuf::from("ruby/app/views/foos/show.html.erb"), "Bar".to_owned()), + (PathBuf::from("ruby/app/views/foos/_row.html.erb"), "Bam".to_owned()), ]), Source::TeamFile, )]; diff --git a/src/project_builder.rs b/src/project_builder.rs index 9560333..9c44859 100644 --- a/src/project_builder.rs +++ b/src/project_builder.rs @@ -19,6 +19,8 @@ use crate::{ type AbsolutePath = PathBuf; type RelativePath = PathBuf; + +#[derive(Debug)] enum EntryType { Directory(AbsolutePath, RelativePath), RubyPackage(AbsolutePath, RelativePath), @@ -120,7 +122,6 @@ impl<'a> ProjectBuilder<'a> { if let Some(report) = maybe_error { return Err(report); } - self.build_project_from_entry_types(entry_types) } diff --git a/src/project_file_builder.rs b/src/project_file_builder.rs index 05269bb..fc69cc3 100644 --- a/src/project_file_builder.rs +++ b/src/project_file_builder.rs @@ -13,7 +13,8 @@ pub struct ProjectFileBuilder<'a> { } lazy_static! { - static ref TEAM_REGEX: Regex = Regex::new(r#"^(?:#|//) @team:? (.*)$"#).expect("error compiling regular expression"); + static ref TEAM_REGEX: Regex = + Regex::new(r#"^(?:#|//||%>)?$"#).expect("error compiling regular expression"); } impl<'a> ProjectFileBuilder<'a> { @@ -103,5 +104,23 @@ mod tests { .and_then(|cap| cap.get(1)) .map(|m| m.as_str().to_string()); assert_eq!(owner, Some("Foo".to_string())); + + let owner = TEAM_REGEX + .captures("") + .and_then(|cap| cap.get(1)) + .map(|m| m.as_str().to_string()); + assert_eq!(owner, Some("Foo".to_string())); + + let owner = TEAM_REGEX + .captures("<%# @team: Foo %>") + .and_then(|cap| cap.get(1)) + .map(|m| m.as_str().to_string()); + assert_eq!(owner, Some("Foo".to_string())); + + let owner = TEAM_REGEX + .captures("") + .and_then(|cap| cap.get(1)) + .map(|m| m.as_str().to_string()); + assert_eq!(owner, Some("Foo".to_string())); } } diff --git a/tests/fixtures/valid_project/.github/CODEOWNERS b/tests/fixtures/valid_project/.github/CODEOWNERS index f39bb1f..e0d3d9a 100644 --- a/tests/fixtures/valid_project/.github/CODEOWNERS +++ b/tests/fixtures/valid_project/.github/CODEOWNERS @@ -12,6 +12,9 @@ /javascript/packages/list/page-admin.tsx @PaymentsTeam /ruby/app/models/bank_account.rb @PaymentsTeam /ruby/app/models/payroll.rb @PayrollTeam +/ruby/app/views/foos/edit.erb @PayrollTeam +/ruby/app/views/foos/index.html.erb @UX +/ruby/app/views/foos/new.html.erb @PayrollTeam # Team-specific owned globs /ruby/app/payments/**/* @PaymentsTeam diff --git a/tests/fixtures/valid_project/config/code_ownership.yml b/tests/fixtures/valid_project/config/code_ownership.yml index 05bc791..5799107 100644 --- a/tests/fixtures/valid_project/config/code_ownership.yml +++ b/tests/fixtures/valid_project/config/code_ownership.yml @@ -1,5 +1,5 @@ owned_globs: - - "{gems,config,javascript,ruby,components}/**/*.{rb,tsx}" + - "{gems,config,javascript,ruby,components}/**/*.{rb,tsx,erb}" ruby_package_paths: - ruby/packages/**/* javascript_package_paths: diff --git a/tests/fixtures/valid_project/ruby/app/views/foos/edit.erb b/tests/fixtures/valid_project/ruby/app/views/foos/edit.erb new file mode 100644 index 0000000..453d861 --- /dev/null +++ b/tests/fixtures/valid_project/ruby/app/views/foos/edit.erb @@ -0,0 +1 @@ +<%# @team: Payroll %> \ No newline at end of file diff --git a/tests/fixtures/valid_project/ruby/app/views/foos/index.html.erb b/tests/fixtures/valid_project/ruby/app/views/foos/index.html.erb new file mode 100644 index 0000000..386ea11 --- /dev/null +++ b/tests/fixtures/valid_project/ruby/app/views/foos/index.html.erb @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/tests/fixtures/valid_project/ruby/app/views/foos/new.html.erb b/tests/fixtures/valid_project/ruby/app/views/foos/new.html.erb new file mode 100644 index 0000000..453d861 --- /dev/null +++ b/tests/fixtures/valid_project/ruby/app/views/foos/new.html.erb @@ -0,0 +1 @@ +<%# @team: Payroll %> \ No newline at end of file diff --git a/tests/valid_project_test.rs b/tests/valid_project_test.rs index 795bff9..ebf6bad 100644 --- a/tests/valid_project_test.rs +++ b/tests/valid_project_test.rs @@ -258,6 +258,8 @@ fn test_for_team() -> Result<(), Box> { ## Annotations at the top of file /javascript/packages/PayrollFlow/index.tsx /ruby/app/models/payroll.rb + /ruby/app/views/foos/edit.erb + /ruby/app/views/foos/new.html.erb ## Team-specific owned globs This team owns nothing in this category.