Skip to content

Commit 00b5350

Browse files
authored
Don't create empty sections in CODEOWNERS file (#16)
1 parent 49dac9b commit 00b5350

File tree

2 files changed

+5
-39
lines changed

2 files changed

+5
-39
lines changed

src/ownership/file_generator.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ impl FileGenerator {
1010
lines.append(&mut Self::disclaimer());
1111

1212
for mapper in &self.mappers {
13+
if mapper.entries().is_empty() {
14+
continue;
15+
}
16+
1317
lines.push(format!("# {}", mapper.name()));
1418
lines.append(&mut Self::to_sorted_lines(&mapper.entries()));
1519
lines.push("".to_owned());

src/ownership/tests.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,9 @@ fn test_annotations_at_the_top_of_file() {
124124
"# Annotations at the top of file",
125125
"/packs/payroll/services/runner.rb @Payroll-Eng",
126126
"",
127-
"# Team-specific owned globs",
128-
"",
129-
"# Owner metadata key in package.yml",
130-
"",
131-
"# Owner metadata key in package.json",
132-
"",
133127
"# Team YML ownership",
134128
"/config/teams/payroll.yml @Payroll-Eng",
135129
"",
136-
"# Team owned gems",
137-
"",
138-
"# Owner in .codeowner",
139-
"",
140130
])
141131
.join("\n")
142132
)
@@ -149,22 +139,12 @@ fn test_team_specific_owned_globs() {
149139
assert_eq!(
150140
ownership.generate_file(),
151141
with_disclaimer(vec![
152-
"# Annotations at the top of file",
153-
"",
154142
"# Team-specific owned globs",
155143
"/packs/payroll/** @Payroll-Eng",
156144
"",
157-
"# Owner metadata key in package.yml",
158-
"",
159-
"# Owner metadata key in package.json",
160-
"",
161145
"# Team YML ownership",
162146
"/config/teams/payroll.yml @Payroll-Eng",
163147
"",
164-
"# Team owned gems",
165-
"",
166-
"# Owner in .codeowner",
167-
"",
168148
])
169149
.join("\n")
170150
)
@@ -177,10 +157,6 @@ fn test_owner_metadata_in_package() {
177157
assert_eq!(
178158
ownership.generate_file(),
179159
with_disclaimer(vec![
180-
"# Annotations at the top of file",
181-
"",
182-
"# Team-specific owned globs",
183-
"",
184160
"# Owner metadata key in package.yml",
185161
"/packs/payroll_package/**/** @Payroll-Eng",
186162
"",
@@ -190,10 +166,6 @@ fn test_owner_metadata_in_package() {
190166
"# Team YML ownership",
191167
"/config/teams/payroll.yml @Payroll-Eng",
192168
"",
193-
"# Team owned gems",
194-
"",
195-
"# Owner in .codeowner",
196-
"",
197169
])
198170
.join("\n")
199171
)
@@ -206,22 +178,12 @@ fn test_team_owned_gems() {
206178
assert_eq!(
207179
ownership.generate_file(),
208180
with_disclaimer(vec![
209-
"# Annotations at the top of file",
210-
"",
211-
"# Team-specific owned globs",
212-
"",
213-
"# Owner metadata key in package.yml",
214-
"",
215-
"# Owner metadata key in package.json",
216-
"",
217181
"# Team YML ownership",
218182
"/config/teams/payroll.yml @Payroll-Eng",
219183
"",
220184
"# Team owned gems",
221185
"/components/payroll_calculator/**/** @Payroll-Eng",
222-
"",
223-
"# Owner in .codeowner",
224-
"",
186+
""
225187
])
226188
.join("\n")
227189
)

0 commit comments

Comments
 (0)