Skip to content

Commit

Permalink
[chore] error out on codeowners in allowlist not used anywhere (#30300)
Browse files Browse the repository at this point in the history
**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 #30299

**Testing:**
Manual testing
  • Loading branch information
atoulme committed Jan 4, 2024
1 parent eebda5f commit 0bc65c2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/githubgen/codeowners.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ func (cg codeownersGenerator) generate(data *githubData) error {
allowlistLines := strings.Split(string(allowlistData), "\n")

allowlist := make(map[string]struct{}, len(allowlistLines))
unusedAllowlist := make(map[string]struct{}, len(allowlistLines))
for _, line := range allowlistLines {
if line == "" {
continue
}
allowlist[line] = struct{}{}
unusedAllowlist[line] = struct{}{}
}
var missingCodeowners []string
var duplicateCodeowners []string
Expand All @@ -95,6 +100,7 @@ func (cg codeownersGenerator) generate(data *githubData) error {

if !present {
_, allowed := allowlist[codeowner]
delete(unusedAllowlist, codeowner)
allowed = allowed || strings.HasPrefix(codeowner, "open-telemetry/")
if !allowed {
missingCodeowners = append(missingCodeowners, codeowner)
Expand All @@ -111,6 +117,14 @@ func (cg codeownersGenerator) generate(data *githubData) error {
sort.Strings(duplicateCodeowners)
return fmt.Errorf("codeowners members duplicate in allowlist: %s", strings.Join(duplicateCodeowners, ", "))
}
if len(unusedAllowlist) > 0 {
var unused []string
for k := range unusedAllowlist {
unused = append(unused, k)
}
sort.Strings(unused)
return fmt.Errorf("unused members in allowlist: %s", strings.Join(unused, ", "))
}

codeowners := codeownersHeader
deprecatedList := "## DEPRECATED components\n"
Expand Down

0 comments on commit 0bc65c2

Please sign in to comment.