Skip to content

Commit a39af5b

Browse files
authored
ERB annotation support (#72)
* overrides fixture * overrides prompt * adding verify compare for file * valid project with overrides test * from codeowners only * updating fixtures for overrides * renaming verify to crosscheck * tests for erb * adding erb support * bumping to 0.2.10
1 parent 0746a32 commit a39af5b

File tree

14 files changed

+86
-13
lines changed

14 files changed

+86
-13
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/target
22
.DS_Store
33
/tmp
4+
**/project-file-cache.json

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "codeowners"
3-
version = "0.2.9"
3+
version = "0.2.10"
44
edition = "2024"
55

66
[profile.release]

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: 16 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,20 @@ 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(),
264+
},
265+
TestProjectFile {
266+
relative_path: "ruby/app/views/foos/edit.erb".to_owned(),
267+
content: "<%# @team: Foo %>\n".to_owned(),
268+
},
269+
TestProjectFile {
270+
relative_path: "ruby/app/views/foos/show.html.erb".to_owned(),
271+
content: "<!-- @team: Bar -->\n".to_owned(),
272+
},
273+
TestProjectFile {
274+
relative_path: "ruby/app/views/foos/_row.html.erb".to_owned(),
275+
content: "<!-- @team Bam -->\n".to_owned(),
264276
},
265277
],
266278
);

src/ownership/mapper/team_file_mapper.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,36 @@ mod tests {
9999
team_name: "Bar".to_owned(),
100100
disabled: false,
101101
},
102+
Entry {
103+
path: "packs/bar/comp_colon.rb".to_owned(),
104+
github_team: "@Bar".to_owned(),
105+
team_name: "Bar".to_owned(),
106+
disabled: false,
107+
},
108+
Entry {
109+
path: "packs/jscomponents/comp-colon.ts".to_owned(),
110+
github_team: "@Foo".to_owned(),
111+
team_name: "Foo".to_owned(),
112+
disabled: false,
113+
},
114+
Entry {
115+
path: "ruby/app/views/foos/edit.erb".to_owned(),
116+
github_team: "@Foo".to_owned(),
117+
team_name: "Foo".to_owned(),
118+
disabled: false,
119+
},
120+
Entry {
121+
path: "ruby/app/views/foos/show.html.erb".to_owned(),
122+
github_team: "@Bar".to_owned(),
123+
team_name: "Bar".to_owned(),
124+
disabled: false,
125+
},
126+
Entry {
127+
path: "ruby/app/views/foos/_row.html.erb".to_owned(),
128+
github_team: "@Bam".to_owned(),
129+
team_name: "Bam".to_owned(),
130+
disabled: false,
131+
},
102132
],
103133
);
104134
Ok(())
@@ -114,8 +144,11 @@ mod tests {
114144
(PathBuf::from("packs/[admin]/comp.ts"), "Bar".to_owned()),
115145
(PathBuf::from("packs/bar/comp.rb"), "Bar".to_owned()),
116146
(PathBuf::from("packs/jscomponents/comp.ts"), "Foo".to_owned()),
117-
(PathBuf::from("packs/jscomponents/comp-colon.ts"), "FooColon".to_owned()),
118-
(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()),
149+
(PathBuf::from("ruby/app/views/foos/edit.erb"), "Foo".to_owned()),
150+
(PathBuf::from("ruby/app/views/foos/show.html.erb"), "Bar".to_owned()),
151+
(PathBuf::from("ruby/app/views/foos/_row.html.erb"), "Bam".to_owned()),
119152
]),
120153
Source::TeamFile,
121154
)];

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}"
2+
- "{gems,config,javascript,ruby,components}/**/*.{rb,tsx,erb}"
33
ruby_package_paths:
44
- ruby/packages/**/*
55
javascript_package_paths:

0 commit comments

Comments
 (0)