Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "codeowners"
version = "0.2.8"
version = "0.2.9"
edition = "2024"

[profile.release]
Expand Down
10 changes: 9 additions & 1 deletion src/common_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,21 @@ pub mod tests {
relative_path: "packs/jscomponents/comp.ts".to_owned(),
content: "// @team Foo\n".to_owned(),
},
TestProjectFile {
relative_path: "packs/jscomponents/comp-colon.ts".to_owned(),
content: "// @team: FooColon\n".to_owned(),
},
TestProjectFile {
relative_path: "packs/[admin]/comp.ts".to_owned(),
content: "// @team Bar\n".to_owned(),
},
TestProjectFile {
relative_path: "packs/bar/comp.rb".to_owned(),
content: "// @team Bar\n".to_owned(),
content: "# @team Bar\n".to_owned(),
},
TestProjectFile {
relative_path: "packs/bar/comp-colon.rb".to_owned(),
content: "# @team: BarColon\n".to_owned(),
},
],
);
Expand Down
14 changes: 8 additions & 6 deletions src/ownership/mapper/team_file_mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ impl Mapper for TeamFileMapper {

for owned_file in &self.project.files {
if let Some(ref owner) = owned_file.owner {
let team = team_by_name.get(owner);

if let Some(team) = team {
let relative_path = self.project.relative_path(&owned_file.path);
path_to_team.insert(relative_path.to_owned(), team.name.clone());
}
let relative_path = self.project.relative_path(&owned_file.path);
let team_name = team_by_name
.get(owner)
.map(|team| team.name.clone())
.unwrap_or_else(|| owner.clone());
path_to_team.insert(relative_path.to_owned(), team_name);
}
}

Expand Down Expand Up @@ -114,6 +114,8 @@ 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()),
]),
Source::TeamFile,
)];
Expand Down
219 changes: 0 additions & 219 deletions src/ownership/tests.rs

This file was deleted.

34 changes: 33 additions & 1 deletion src/project_file_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ 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#"^(?:#|//) @team:? (.*)$"#).expect("error compiling regular expression");
}

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

ProjectFile { path: path.clone(), owner }
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_team_regex() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

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("// @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("// @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("# @team: Foo")
.and_then(|cap| cap.get(1))
.map(|m| m.as_str().to_string());
assert_eq!(owner, Some("Foo".to_string()));
}
}
1 change: 1 addition & 0 deletions tests/fixtures/valid_project/.github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# Annotations at the top of file
/javascript/packages/PayrollFlow/index.tsx @PayrollTeam
/javascript/packages/list/page-admin.tsx @PaymentsTeam
/ruby/app/models/bank_account.rb @PaymentsTeam
/ruby/app/models/payroll.rb @PayrollTeam

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// @team: Payments
2 changes: 1 addition & 1 deletion tests/fixtures/valid_project/ruby/app/models/payroll.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @team Payroll
# @team: Payroll

class Payroll; end
1 change: 0 additions & 1 deletion tests/invalid_project_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fn test_validate() -> Result<(), Box<dyn Error>> {
- ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'

Some files are missing ownership
- ruby/app/models/blockchain.rb
- ruby/app/unowned.rb

"}));
Expand Down