Skip to content

Commit b8aa413

Browse files
committed
adding erb support
1 parent 0a754fc commit b8aa413

File tree

10 files changed

+42
-18
lines changed

10 files changed

+42
-18
lines changed

dev/run_benchmarks_for_gv.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ echo "To run these benchmarks on your application, you can place this repo next
99

1010
hyperfine --warmup=2 --runs=3 --export-markdown tmp/codeowners_benchmarks_gv.md \
1111
'../rubyatscale/codeowners-rs/target/release/codeowners gv' \
12-
'bin/codeownership validate' \
13-
'bin/codeowners-rs gv'
12+
'bin/codeownership validate'

src/common_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub mod tests {
3131
const DEFAULT_CODE_OWNERSHIP_YML: &str = indoc! {"
3232
---
3333
owned_globs:
34-
- \"{app,components,config,frontend,lib,packs,spec}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml}\"
34+
- \"{app,components,config,frontend,lib,packs,spec,ruby}/**/*.{rb,rake,js,jsx,ts,tsx,json,yml,erb}\"
3535
unowned_globs:
3636
- config/code_ownership.yml
3737
javascript_package_paths:
@@ -248,7 +248,7 @@ pub mod tests {
248248
},
249249
TestProjectFile {
250250
relative_path: "packs/jscomponents/comp-colon.ts".to_owned(),
251-
content: "// @team: FooColon\n".to_owned(),
251+
content: "// @team: Foo\n".to_owned(),
252252
},
253253
TestProjectFile {
254254
relative_path: "packs/[admin]/comp.ts".to_owned(),
@@ -259,8 +259,8 @@ pub mod tests {
259259
content: "# @team Bar\n".to_owned(),
260260
},
261261
TestProjectFile {
262-
relative_path: "packs/bar/comp-colon.rb".to_owned(),
263-
content: "# @team: BarColon\n".to_owned(),
262+
relative_path: "packs/bar/comp_colon.rb".to_owned(),
263+
content: "# @team: Bar\n".to_owned(),
264264
},
265265
TestProjectFile {
266266
relative_path: "ruby/app/views/foos/edit.erb".to_owned(),

src/ownership/mapper/team_file_mapper.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ mod tests {
100100
disabled: false,
101101
},
102102
Entry {
103-
path: "packs/bar/comp-colon.rb".to_owned(),
104-
github_team: "@BarColon".to_owned(),
105-
team_name: "BarColon".to_owned(),
103+
path: "packs/bar/comp_colon.rb".to_owned(),
104+
github_team: "@Bar".to_owned(),
105+
team_name: "Bar".to_owned(),
106106
disabled: false,
107107
},
108108
Entry {
109109
path: "packs/jscomponents/comp-colon.ts".to_owned(),
110-
github_team: "@FooColon".to_owned(),
111-
team_name: "FooColon".to_owned(),
110+
github_team: "@Foo".to_owned(),
111+
team_name: "Foo".to_owned(),
112112
disabled: false,
113113
},
114114
Entry {
@@ -144,8 +144,8 @@ mod tests {
144144
(PathBuf::from("packs/[admin]/comp.ts"), "Bar".to_owned()),
145145
(PathBuf::from("packs/bar/comp.rb"), "Bar".to_owned()),
146146
(PathBuf::from("packs/jscomponents/comp.ts"), "Foo".to_owned()),
147-
(PathBuf::from("packs/jscomponents/comp-colon.ts"), "FooColon".to_owned()),
148-
(PathBuf::from("packs/bar/comp-colon.rb"), "BarColon".to_owned()),
147+
(PathBuf::from("packs/jscomponents/comp-colon.ts"), "Foo".to_owned()),
148+
(PathBuf::from("packs/bar/comp_colon.rb"), "Bar".to_owned()),
149149
(PathBuf::from("ruby/app/views/foos/edit.erb"), "Foo".to_owned()),
150150
(PathBuf::from("ruby/app/views/foos/show.html.erb"), "Bar".to_owned()),
151151
(PathBuf::from("ruby/app/views/foos/_row.html.erb"), "Bam".to_owned()),

src/project_builder.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use crate::{
1919

2020
type AbsolutePath = PathBuf;
2121
type RelativePath = PathBuf;
22+
23+
#[derive(Debug)]
2224
enum EntryType {
2325
Directory(AbsolutePath, RelativePath),
2426
RubyPackage(AbsolutePath, RelativePath),
@@ -120,7 +122,6 @@ impl<'a> ProjectBuilder<'a> {
120122
if let Some(report) = maybe_error {
121123
return Err(report);
122124
}
123-
124125
self.build_project_from_entry_types(entry_types)
125126
}
126127

src/project_file_builder.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub struct ProjectFileBuilder<'a> {
1313
}
1414

1515
lazy_static! {
16-
static ref TEAM_REGEX: Regex = Regex::new(r#"^(?:#|//) @team:? (.*)$"#).expect("error compiling regular expression");
16+
static ref TEAM_REGEX: Regex =
17+
Regex::new(r#"^(?:#|//|<!--|<%#)\s*@team:?\s*(.*?)\s*(?:-->|%>)?$"#).expect("error compiling regular expression");
1718
}
1819

1920
impl<'a> ProjectFileBuilder<'a> {
@@ -103,5 +104,23 @@ mod tests {
103104
.and_then(|cap| cap.get(1))
104105
.map(|m| m.as_str().to_string());
105106
assert_eq!(owner, Some("Foo".to_string()));
107+
108+
let owner = TEAM_REGEX
109+
.captures("<!-- @team: Foo -->")
110+
.and_then(|cap| cap.get(1))
111+
.map(|m| m.as_str().to_string());
112+
assert_eq!(owner, Some("Foo".to_string()));
113+
114+
let owner = TEAM_REGEX
115+
.captures("<%# @team: Foo %>")
116+
.and_then(|cap| cap.get(1))
117+
.map(|m| m.as_str().to_string());
118+
assert_eq!(owner, Some("Foo".to_string()));
119+
120+
let owner = TEAM_REGEX
121+
.captures("<!-- @team Foo -->")
122+
.and_then(|cap| cap.get(1))
123+
.map(|m| m.as_str().to_string());
124+
assert_eq!(owner, Some("Foo".to_string()));
106125
}
107126
}

tests/fixtures/valid_project/.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
/javascript/packages/list/page-admin.tsx @PaymentsTeam
1313
/ruby/app/models/bank_account.rb @PaymentsTeam
1414
/ruby/app/models/payroll.rb @PayrollTeam
15+
/ruby/app/views/foos/edit.erb @PayrollTeam
16+
/ruby/app/views/foos/index.html.erb @UX
17+
/ruby/app/views/foos/new.html.erb @PayrollTeam
1518

1619
# Team-specific owned globs
1720
/ruby/app/payments/**/* @PaymentsTeam

tests/fixtures/valid_project/config/code_ownership.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
owned_globs:
2-
- "{gems,config,javascript,ruby,components}/**/*.{rb,tsx,erb,html.erb}"
2+
- "{gems,config,javascript,ruby,components}/**/*.{rb,tsx,erb}"
33
ruby_package_paths:
44
- ruby/packages/**/*
55
javascript_package_paths:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%# @team: Payments %>
1+
<%# @team: Payroll %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<!-- @team: UX -->
1+
<!-- @team UX -->

tests/valid_project_test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ fn test_for_team() -> Result<(), Box<dyn Error>> {
258258
## Annotations at the top of file
259259
/javascript/packages/PayrollFlow/index.tsx
260260
/ruby/app/models/payroll.rb
261+
/ruby/app/views/foos/edit.erb
262+
/ruby/app/views/foos/new.html.erb
261263
262264
## Team-specific owned globs
263265
This team owns nothing in this category.

0 commit comments

Comments
 (0)