Skip to content

Commit 9ad8d29

Browse files
committed
handling unowned description
1 parent 727fb95 commit 9ad8d29

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/ownership.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,17 @@ impl TeamOwnership {
5151

5252
impl Display for FileOwner {
5353
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54-
let sources = self
55-
.sources
56-
.iter()
57-
.sorted_by_key(|source| source.to_string())
58-
.map(|source| source.to_string())
59-
.collect::<Vec<String>>()
60-
.join("\n- ");
54+
let sources = if self.sources.is_empty() {
55+
"Unowned".to_string()
56+
} else {
57+
self.sources
58+
.iter()
59+
.sorted_by_key(|source| source.to_string())
60+
.map(|source| source.to_string())
61+
.collect::<Vec<_>>()
62+
.join("\n- ")
63+
};
64+
6165
write!(
6266
f,
6367
"Team: {}\nTeam YML: {}\nDescription:\n- {}",

tests/invalid_project_test.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
5252
.stdout(predicate::eq(indoc! {"
5353
Team: Unowned
5454
Team YML: Unowned
55-
Description:\n- \n"})); // trailing whitespace
55+
Description:
56+
- Unowned
57+
"}));
5658
Ok(())
5759
}
5860

tests/valid_project_test.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,20 @@ fn test_for_file() -> Result<(), Box<dyn Error>> {
5454

5555
#[test]
5656
fn test_for_file_same_team_multiple_ownerships() -> Result<(), Box<dyn Error>> {
57-
let expected_output = r#"
58-
Team: Payroll
59-
Team YML: config/teams/payroll.yml
60-
Description:
61-
- Owner annotation at the top of the file
62-
- Owner defined in `javascript/packages/PayrollFlow/package.json` with implicity owned glob: `javascript/packages/PayrollFlow/**/**`
63-
"#
64-
.trim();
6557
Command::cargo_bin("codeowners")?
6658
.arg("--project-root")
6759
.arg("tests/fixtures/valid_project")
6860
.arg("for-file")
6961
.arg("javascript/packages/PayrollFlow/index.tsx")
7062
.assert()
7163
.success()
72-
.stdout(predicate::str::contains(expected_output));
64+
.stdout(predicate::eq(indoc! {"
65+
Team: Payroll
66+
Team YML: config/teams/payroll.yml
67+
Description:
68+
- Owner annotation at the top of the file
69+
- Owner defined in `javascript/packages/PayrollFlow/package.json` with implicity owned glob: `javascript/packages/PayrollFlow/**/**`
70+
"}));
7371
Ok(())
7472
}
7573

@@ -82,8 +80,13 @@ fn test_for_file_with_2_ownerships() -> Result<(), Box<dyn Error>> {
8280
.arg("javascript/packages/PayrollFlow/index.tsx")
8381
.assert()
8482
.success()
85-
.stdout(predicate::str::contains("Team: Payroll"))
86-
.stdout(predicate::str::contains("Team YML: config/teams/payroll.yml"));
83+
.stdout(predicate::eq(indoc! {"
84+
Team: Payroll
85+
Team YML: config/teams/payroll.yml
86+
Description:
87+
- Owner annotation at the top of the file
88+
- Owner defined in `javascript/packages/PayrollFlow/package.json` with implicity owned glob: `javascript/packages/PayrollFlow/**/**`
89+
"}));
8790

8891
Ok(())
8992
}

0 commit comments

Comments
 (0)