Skip to content

Commit 0bc65c2

Browse files
authored
[chore] error out on codeowners in allowlist not used anywhere (open-telemetry#30300)
**Description:** When running `make gengithub`, we now check if members of the allowlist are not referenced anywhere. ``` $> make gengithub cd cmd/githubgen && go install . githubgen 2024/01/04 12:12:20 unused members in allowlist: , Doron-Bargo, keep94, oded-dd, thepeterstone make: *** [gengithub] Error 1 ``` **Link to tracking Issue:** Fixes open-telemetry#30299 **Testing:** Manual testing
1 parent eebda5f commit 0bc65c2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmd/githubgen/codeowners.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ func (cg codeownersGenerator) generate(data *githubData) error {
8181
allowlistLines := strings.Split(string(allowlistData), "\n")
8282

8383
allowlist := make(map[string]struct{}, len(allowlistLines))
84+
unusedAllowlist := make(map[string]struct{}, len(allowlistLines))
8485
for _, line := range allowlistLines {
86+
if line == "" {
87+
continue
88+
}
8589
allowlist[line] = struct{}{}
90+
unusedAllowlist[line] = struct{}{}
8691
}
8792
var missingCodeowners []string
8893
var duplicateCodeowners []string
@@ -95,6 +100,7 @@ func (cg codeownersGenerator) generate(data *githubData) error {
95100

96101
if !present {
97102
_, allowed := allowlist[codeowner]
103+
delete(unusedAllowlist, codeowner)
98104
allowed = allowed || strings.HasPrefix(codeowner, "open-telemetry/")
99105
if !allowed {
100106
missingCodeowners = append(missingCodeowners, codeowner)
@@ -111,6 +117,14 @@ func (cg codeownersGenerator) generate(data *githubData) error {
111117
sort.Strings(duplicateCodeowners)
112118
return fmt.Errorf("codeowners members duplicate in allowlist: %s", strings.Join(duplicateCodeowners, ", "))
113119
}
120+
if len(unusedAllowlist) > 0 {
121+
var unused []string
122+
for k := range unusedAllowlist {
123+
unused = append(unused, k)
124+
}
125+
sort.Strings(unused)
126+
return fmt.Errorf("unused members in allowlist: %s", strings.Join(unused, ", "))
127+
}
114128

115129
codeowners := codeownersHeader
116130
deprecatedList := "## DEPRECATED components\n"

0 commit comments

Comments
 (0)