Skip to content

Commit 8bfd0a7

Browse files
committed
test for gems override
1 parent e4244ee commit 8bfd0a7

File tree

7 files changed

+50
-20
lines changed

7 files changed

+50
-20
lines changed

src/ownership/fast.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,31 +144,28 @@ fn load_teams(project_root: &Path, team_file_globs: &[String]) -> std::result::R
144144
}
145145

146146
lazy_static! {
147-
static ref TOP_OF_FILE_TEAM_AT_REGEX: Option<Regex> = Regex::new(r#"^(?:#|//)\s*@team\s+(.+)$"#).ok();
148-
static ref TOP_OF_FILE_TEAM_COLON_REGEX: Option<Regex> = Regex::new(r#"(?i)^(?:#|//)\s*team\s*:\s*(.+)$"#).ok();
147+
// Allow optional leading whitespace before the comment marker
148+
static ref TOP_OF_FILE_TEAM_AT_REGEX: Option<Regex> = Regex::new(r#"^\s*(?:#|//)\s*@team\s+(.+)$"#).ok();
149+
static ref TOP_OF_FILE_TEAM_COLON_REGEX: Option<Regex> = Regex::new(r#"(?i)^\s*(?:#|//)\s*team\s*:\s*(.+)$"#).ok();
149150
}
150151

151152
fn read_top_of_file_team(path: &Path) -> Option<String> {
152153
let content = fs::read_to_string(path).ok()?;
153-
for line in content.lines().take(15) {
154-
if let Some(re) = &*TOP_OF_FILE_TEAM_AT_REGEX {
155-
if let Some(cap) = re.captures(line) {
156-
if let Some(m) = cap.get(1) {
157-
return Some(m.as_str().to_string());
158-
}
154+
let line = content.lines().next()?;
155+
156+
if let Some(re) = &*TOP_OF_FILE_TEAM_AT_REGEX {
157+
if let Some(cap) = re.captures(line) {
158+
if let Some(m) = cap.get(1) {
159+
return Some(m.as_str().to_string());
159160
}
160161
}
161-
if let Some(re) = &*TOP_OF_FILE_TEAM_COLON_REGEX {
162-
if let Some(cap) = re.captures(line) {
163-
if let Some(m) = cap.get(1) {
164-
return Some(m.as_str().to_string());
165-
}
162+
}
163+
if let Some(re) = &*TOP_OF_FILE_TEAM_COLON_REGEX {
164+
if let Some(cap) = re.captures(line) {
165+
if let Some(m) = cap.get(1) {
166+
return Some(m.as_str().to_string());
166167
}
167168
}
168-
let trimmed = line.trim_start();
169-
if !(trimmed.starts_with('#') || trimmed.starts_with("//") || trimmed.is_empty()) {
170-
break;
171-
}
172169
}
173170
None
174171
}

src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn for_file(run_config: &RunConfig, file_path: &str, fast: bool) -> RunResul
3939
if fast {
4040
for_file_from_codeowners(run_config, file_path)
4141
} else {
42-
// run_with_runner(run_config, |runner| runner.for_file(file_path))
42+
//run_with_runner(run_config, |runner| runner.for_file(file_path))
4343
for_file_optimized(run_config, file_path)
4444
}
4545
}

tests/fixtures/valid_project/.github/CODEOWNERS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
# Team YML ownership
3131
/config/teams/payments.yml @PaymentsTeam
3232
/config/teams/payroll.yml @PayrollTeam
33+
/config/teams/ux.yml @UX
3334

3435
# Team owned gems
3536
/gems/payroll_calculator/**/** @PayrollTeam
37+
/gems/pets/**/** @UX
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
owned_globs:
2-
- "{gems,config,javascript,ruby}/**/*.{rb,tsx}"
2+
- "{gems,config,javascript,ruby,components}/**/*.{rb,tsx}"
33
ruby_package_paths:
44
- ruby/packages/**/*
55
javascript_package_paths:
66
- javascript/packages/**
77
team_file_glob:
88
- config/teams/**/*.yml
9-
vendored_gems_path: gems
9+
unbuilt_gems_path: gems
1010
unowned_globs:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: UX
2+
github:
3+
team: '@UX'
4+
ruby:
5+
owned_gems:
6+
- pets
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# generated
2+
# next line should be ignored
3+
# @team Payments
4+
5+
class Dog; end

tests/valid_project_test.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,26 @@ fn test_fast_for_file_full_path() -> Result<(), Box<dyn Error>> {
138138
Ok(())
139139
}
140140

141+
#[test]
142+
fn test_for_file_with_components() -> Result<(), Box<dyn Error>> {
143+
Command::cargo_bin("codeowners")?
144+
.arg("--project-root")
145+
.arg("tests/fixtures/valid_project")
146+
.arg("--no-cache")
147+
.arg("for-file")
148+
.arg("gems/pets/dog.rb")
149+
.assert()
150+
.success()
151+
.stdout(predicate::eq(indoc! {"
152+
Team: UX
153+
Github Team: @UX
154+
Team YML: config/teams/ux.yml
155+
Description:
156+
- Owner specified in Team YML's `owned_gems`
157+
"}));
158+
Ok(())
159+
}
160+
141161
#[test]
142162
fn test_for_file_same_team_multiple_ownerships() -> Result<(), Box<dyn Error>> {
143163
Command::cargo_bin("codeowners")?

0 commit comments

Comments
 (0)