Skip to content

Commit 210252a

Browse files
authored
Improve code owner "source" descriptions (#36)
* providing location of package file * improving glob source descriptions
1 parent b0899d3 commit 210252a

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

src/ownership.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl Display for FileOwner {
4242
.join(", ");
4343
write!(
4444
f,
45-
"Team: {}\nTeam YML: {}\nSource(s): {}",
45+
"Team: {}\nTeam YML: {}\nDescription: {}",
4646
self.team_name, self.team_config_file_path, sources
4747
)
4848
}

src/ownership/mapper.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ pub enum Source {
3434
Directory(String),
3535
TeamFile,
3636
TeamGem,
37-
TeamGlob,
37+
TeamGlob(String),
3838
Package(String, String),
3939
TeamYml,
4040
}
4141

4242
impl Display for Source {
4343
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4444
match self {
45-
Source::Directory(path) => write!(f, "DirectoryMapper({})", path),
46-
Source::TeamFile => write!(f, "TeamFileMapper"),
47-
Source::TeamGem => write!(f, "TeamGemMapper"),
48-
Source::TeamGlob => write!(f, "TeamGlobMapper"),
49-
Source::Package(file_type, path) => write!(f, "PackageMapper({}, glob: {})", file_type, path),
50-
Source::TeamYml => write!(f, "TeamYmlMapper"),
45+
Source::Directory(path) => write!(f, "Owner specified in `{}/.codeowner`", path),
46+
Source::TeamFile => write!(f, "Owner annotation at the top of the file"),
47+
Source::TeamGem => write!(f, "Owner specified in Team YML's `owned_gems`"),
48+
Source::TeamGlob(glob) => write!(f, "Owner specified in Team YML as an owned_glob `{}`", glob),
49+
Source::Package(package_path, glob) => {
50+
write!(f, "Owner defined in `{}` with implicity owned glob: `{}`", package_path, glob)
51+
}
52+
Source::TeamYml => write!(f, "Teams own their configuration files"),
5153
}
5254
}
5355
}
@@ -131,14 +133,20 @@ mod tests {
131133

132134
#[test]
133135
fn display_source() {
134-
assert_eq!(Source::Directory("packs/bam".to_string()).to_string(), "DirectoryMapper(packs/bam)");
135-
assert_eq!(Source::TeamFile.to_string(), "TeamFileMapper");
136-
assert_eq!(Source::TeamGem.to_string(), "TeamGemMapper");
137-
assert_eq!(Source::TeamGlob.to_string(), "TeamGlobMapper");
138136
assert_eq!(
139-
Source::Package("Ruby".to_string(), "packs/bam/**/**".to_string()).to_string(),
140-
"PackageMapper(Ruby, glob: packs/bam/**/**)"
137+
Source::Directory("packs/bam".to_string()).to_string(),
138+
"Owner specified in `packs/bam/.codeowner`"
139+
);
140+
assert_eq!(Source::TeamFile.to_string(), "Owner annotation at the top of the file");
141+
assert_eq!(Source::TeamGem.to_string(), "Owner specified in Team YML's `owned_gems`");
142+
assert_eq!(
143+
Source::TeamGlob("a/glob/**".to_string()).to_string(),
144+
"Owner specified in Team YML as an owned_glob `a/glob/**`"
145+
);
146+
assert_eq!(
147+
Source::Package("packs/bam/packag.yml".to_string(), "packs/bam/**/**".to_string()).to_string(),
148+
"Owner defined in `packs/bam/packag.yml` with implicity owned glob: `packs/bam/**/**`"
141149
);
142-
assert_eq!(Source::TeamYml.to_string(), "TeamYmlMapper");
150+
assert_eq!(Source::TeamYml.to_string(), "Teams own their configuration files");
143151
}
144152
}

src/ownership/mapper/package_mapper.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl PackageMapper {
104104
owner_matchers.push(OwnerMatcher::Glob {
105105
glob: format!("{}/**/**", package_root),
106106
team_name: team.name.to_owned(),
107-
source: Source::Package(package_type.to_string(), format!("{}/**/**", package_root)),
107+
source: Source::Package(package.path.to_string_lossy().to_string(), format!("{}/**/**", package_root)),
108108
});
109109
}
110110
}
@@ -201,12 +201,12 @@ mod tests {
201201
OwnerMatcher::Glob {
202202
glob: "packs/bam/**/**".to_owned(),
203203
team_name: "Bam".to_owned(),
204-
source: Source::Package("Ruby".to_owned(), "packs/bam/**/**".to_owned()),
204+
source: Source::Package("packs/bam/package.yml".to_owned(), "packs/bam/**/**".to_owned()),
205205
},
206206
OwnerMatcher::Glob {
207207
glob: "packs/foo/**/**".to_owned(),
208208
team_name: "Baz".to_owned(),
209-
source: Source::Package("Ruby".to_owned(), "packs/foo/**/**".to_owned()),
209+
source: Source::Package("packs/foo/package.yml".to_owned(), "packs/foo/**/**".to_owned()),
210210
},
211211
],
212212
);

src/ownership/mapper/team_glob_mapper.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Mapper for TeamGlobMapper {
4040
owner_matchers.push(OwnerMatcher::Glob {
4141
glob: owned_glob.clone(),
4242
team_name: team.github_team.clone(),
43-
source: Source::TeamGlob,
43+
source: Source::TeamGlob(owned_glob.clone()),
4444
})
4545
}
4646
}
@@ -85,7 +85,7 @@ mod tests {
8585
&vec![OwnerMatcher::Glob {
8686
glob: "packs/bar/**".to_owned(),
8787
team_name: "@Baz".to_owned(),
88-
source: Source::TeamGlob,
88+
source: Source::TeamGlob("packs/bar/**".to_owned()),
8989
}],
9090
);
9191
Ok(())

tests/invalid_project_test.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,30 @@ fn test_validate() -> Result<(), Box<dyn Error>> {
1010
.arg("validate")
1111
.assert()
1212
.failure()
13-
.stdout(predicate::str::contains("CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file"))
14-
.stdout(predicate::str::contains("Some files are missing ownership\n- ruby/app/models/blockchain.rb\n- ruby/app/unowned.rb"))
15-
.stdout(predicate::str::contains("Found invalid team annotations\n- ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'"))
16-
.stdout(predicate::str::contains("Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways\n- gems/payroll_calculator/calculator.rb (owner: Payments, source: TeamFileMapper)\n- gems/payroll_calculator/calculator.rb (owner: Payroll, source: TeamGemMapper)"));
13+
.stdout(predicate::str::contains(
14+
"CODEOWNERS out of date. Run `codeowners generate` to update the CODEOWNERS file",
15+
))
16+
.stdout(predicate::str::contains(
17+
"Some files are missing ownership\n- ruby/app/models/blockchain.rb\n- ruby/app/unowned.rb",
18+
))
19+
.stdout(predicate::str::contains(
20+
"Found invalid team annotations\n- ruby/app/models/blockchain.rb is referencing an invalid team - 'Web3'",
21+
))
22+
.stdout(predicate::str::contains(
23+
"Code ownership should only be defined for each file in one way. The following files have declared ownership in multiple ways",
24+
))
25+
.stdout(predicate::str::contains(
26+
"gems/payroll_calculator/calculator.rb (owner: Payments, source: Owner annotation at the top of the file)",
27+
))
28+
.stdout(predicate::str::contains(
29+
"gems/payroll_calculator/calculator.rb (owner: Payroll, source: Owner specified in Team YML's `owned_gems`)",
30+
))
31+
.stdout(predicate::str::contains(
32+
"ruby/app/services/multi_owned.rb (owner: Payments, source: Owner annotation at the top of the file)",
33+
))
34+
.stdout(predicate::str::contains(
35+
"ruby/app/services/multi_owned.rb (owner: Payroll, source: Owner specified in `ruby/app/services/.codeowner`",
36+
));
1737

1838
Ok(())
1939
}
@@ -45,10 +65,12 @@ fn test_for_file_multiple_owners() -> Result<(), Box<dyn Error>> {
4565
.stdout(predicate::str::contains("Error: file is owned by multiple teams!"))
4666
.stdout(predicate::str::contains("Team: Payments"))
4767
.stdout(predicate::str::contains("Team YML: config/teams/payments.yml"))
48-
.stdout(predicate::str::contains("Source(s): TeamFileMapper"))
68+
.stdout(predicate::str::contains("Description: Owner annotation at the top of the file"))
4969
.stdout(predicate::str::contains("Team: Payroll"))
5070
.stdout(predicate::str::contains("Team YML: config/teams/payroll.yml"))
51-
.stdout(predicate::str::contains("Source(s): DirectoryMapper(ruby/app/services)"));
71+
.stdout(predicate::str::contains(
72+
"Description: Owner specified in `ruby/app/services/.codeowner`",
73+
));
5274

5375
Ok(())
5476
}

0 commit comments

Comments
 (0)