Skip to content

Commit 0746a32

Browse files
authored
Allow colon after @team (#71)
* overrides fixture * adding verify compare for file * valid project with overrides test * from codeowners only * updating fixtures for overrides * renaming verify to crosscheck * allow colon after @team * 0.2.9
1 parent fc4e148 commit 0746a32

File tree

10 files changed

+55
-231
lines changed

10 files changed

+55
-231
lines changed

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.8"
3+
version = "0.2.9"
44
edition = "2024"
55

66
[profile.release]

src/common_test.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,13 +246,21 @@ pub mod tests {
246246
relative_path: "packs/jscomponents/comp.ts".to_owned(),
247247
content: "// @team Foo\n".to_owned(),
248248
},
249+
TestProjectFile {
250+
relative_path: "packs/jscomponents/comp-colon.ts".to_owned(),
251+
content: "// @team: FooColon\n".to_owned(),
252+
},
249253
TestProjectFile {
250254
relative_path: "packs/[admin]/comp.ts".to_owned(),
251255
content: "// @team Bar\n".to_owned(),
252256
},
253257
TestProjectFile {
254258
relative_path: "packs/bar/comp.rb".to_owned(),
255-
content: "// @team Bar\n".to_owned(),
259+
content: "# @team Bar\n".to_owned(),
260+
},
261+
TestProjectFile {
262+
relative_path: "packs/bar/comp-colon.rb".to_owned(),
263+
content: "# @team: BarColon\n".to_owned(),
256264
},
257265
],
258266
);

src/ownership/mapper/team_file_mapper.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ impl Mapper for TeamFileMapper {
5050

5151
for owned_file in &self.project.files {
5252
if let Some(ref owner) = owned_file.owner {
53-
let team = team_by_name.get(owner);
54-
55-
if let Some(team) = team {
56-
let relative_path = self.project.relative_path(&owned_file.path);
57-
path_to_team.insert(relative_path.to_owned(), team.name.clone());
58-
}
53+
let relative_path = self.project.relative_path(&owned_file.path);
54+
let team_name = team_by_name
55+
.get(owner)
56+
.map(|team| team.name.clone())
57+
.unwrap_or_else(|| owner.clone());
58+
path_to_team.insert(relative_path.to_owned(), team_name);
5959
}
6060
}
6161

@@ -114,6 +114,8 @@ mod tests {
114114
(PathBuf::from("packs/[admin]/comp.ts"), "Bar".to_owned()),
115115
(PathBuf::from("packs/bar/comp.rb"), "Bar".to_owned()),
116116
(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()),
117119
]),
118120
Source::TeamFile,
119121
)];

src/ownership/tests.rs

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

src/project_file_builder.rs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ 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 = Regex::new(r#"^(?:#|//) @team:? (.*)$"#).expect("error compiling regular expression");
1717
}
1818

1919
impl<'a> ProjectFileBuilder<'a> {
@@ -73,3 +73,35 @@ pub(crate) fn build_project_file_without_cache(path: &PathBuf) -> ProjectFile {
7373

7474
ProjectFile { path: path.clone(), owner }
7575
}
76+
77+
#[cfg(test)]
78+
mod tests {
79+
use super::*;
80+
81+
#[test]
82+
fn test_team_regex() {
83+
let owner = TEAM_REGEX
84+
.captures("// @team Foo")
85+
.and_then(|cap| cap.get(1))
86+
.map(|m| m.as_str().to_string());
87+
assert_eq!(owner, Some("Foo".to_string()));
88+
89+
let owner = TEAM_REGEX
90+
.captures("// @team Foo")
91+
.and_then(|cap| cap.get(1))
92+
.map(|m| m.as_str().to_string());
93+
assert_eq!(owner, Some("Foo".to_string()));
94+
95+
let owner = TEAM_REGEX
96+
.captures("// @team: Foo")
97+
.and_then(|cap| cap.get(1))
98+
.map(|m| m.as_str().to_string());
99+
assert_eq!(owner, Some("Foo".to_string()));
100+
101+
let owner = TEAM_REGEX
102+
.captures("# @team: Foo")
103+
.and_then(|cap| cap.get(1))
104+
.map(|m| m.as_str().to_string());
105+
assert_eq!(owner, Some("Foo".to_string()));
106+
}
107+
}

tests/fixtures/valid_project/.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# Annotations at the top of file
1111
/javascript/packages/PayrollFlow/index.tsx @PayrollTeam
12+
/javascript/packages/list/page-admin.tsx @PaymentsTeam
1213
/ruby/app/models/bank_account.rb @PaymentsTeam
1314
/ruby/app/models/payroll.rb @PayrollTeam
1415

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// @team: Payments
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# @team Payroll
1+
# @team: Payroll
22

33
class Payroll; end

tests/invalid_project_test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ fn test_validate() -> Result<(), Box<dyn Error>> {
3434
- ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'
3535
3636
Some files are missing ownership
37-
- ruby/app/models/blockchain.rb
3837
- ruby/app/unowned.rb
3938
4039
"}));

0 commit comments

Comments
 (0)