diff --git a/tools/populate-owners/README.md b/tools/populate-owners/README.md index 7bbbc94801ce..068505a0d211 100644 --- a/tools/populate-owners/README.md +++ b/tools/populate-owners/README.md @@ -23,7 +23,7 @@ For example, if [openshift/origin][] and [openshift/installer][] both defined an After namespacing aliases, the utility writes `OWNERS_ALIASES` to the root of this repository. If no upstreams define aliases, then the utility removes `OWNER_ALIASES` from the root of this repository. -The utility also iterates through the `ci-operator/jobs/{organization}/{repository}` and `ci-operator/config/{organization}/{repository}` directories, writing `OWNERS` to reflect the upstream configuration. +The utility also iterates through the `ci-operator/{type}/{organization}/{repository}` for `{type}` in `config`, `jobs`, and `templates`, writing `OWNERS` to reflect the upstream configuration. If the upstream did not have an `OWNERS` file, the utility removes the associated `ci-operator/*/{organization}/{repository}/OWNERS`. [openshift/origin]: https://github.com/openshift/origin diff --git a/tools/populate-owners/main.go b/tools/populate-owners/main.go index fcde596f0fc7..279e542a3ef5 100644 --- a/tools/populate-owners/main.go +++ b/tools/populate-owners/main.go @@ -93,15 +93,17 @@ func orgRepos(dir string) (orgRepos []*orgRepo, err error) { return orgRepos, err } -func (orgRepo *orgRepo) getConfig(dir string) (err error) { - path := filepath.Join(dir, orgRepo.Organization, orgRepo.Repository) - info, err := os.Stat(path) - if err != nil { - return err - } +func (orgRepo *orgRepo) getDirectories(dirs ...string) (err error) { + for _, dir := range dirs { + path := filepath.Join(dir, orgRepo.Organization, orgRepo.Repository) + info, err := os.Stat(path) + if err != nil { + return err + } - if info.IsDir() { - orgRepo.Directories = append(orgRepo.Directories, path) + if info.IsDir() { + orgRepo.Directories = append(orgRepo.Directories, path) + } } return nil @@ -305,14 +307,16 @@ func pullOwners(directory string) (err error) { return err } - orgRepos, err := orgRepos(filepath.Join(repoRoot, "ci-operator", "jobs")) + operatorRoot := filepath.Join(repoRoot, "ci-operator") + orgRepos, err := orgRepos(filepath.Join(operatorRoot, "jobs")) if err != nil { return err } - config := filepath.Join(repoRoot, "ci-operator", "config") + config := filepath.Join(operatorRoot, "config") + templates := filepath.Join(operatorRoot, "templates") for _, orgRepo := range orgRepos { - err = orgRepo.getConfig(config) + err = orgRepo.getDirectories(config, templates) if err != nil && !os.IsNotExist(err) { return err } diff --git a/tools/populate-owners/main_test.go b/tools/populate-owners/main_test.go index 333a46a432f2..c77286e79f0a 100644 --- a/tools/populate-owners/main_test.go +++ b/tools/populate-owners/main_test.go @@ -92,7 +92,7 @@ func TestOrgRepos(t *testing.T) { assertEqual(t, orgRepos, expected) } -func TestGetConfig(t *testing.T) { +func TestGetDirectories(t *testing.T) { dir, err := ioutil.TempDir("", "populate-owners-") if err != nil { t.Fatal(err) @@ -105,7 +105,7 @@ func TestGetConfig(t *testing.T) { t.Fatal(err) } - for _, test := range []struct{ + for _, test := range []struct { name string input *orgRepo expected *orgRepo @@ -139,8 +139,8 @@ func TestGetConfig(t *testing.T) { error: regexp.MustCompile("^stat .*/c/d: no such file or directory"), }, } { - t.Run(test.name, func (t *testing.T) { - err := test.input.getConfig(dir) + t.Run(test.name, func(t *testing.T) { + err := test.input.getDirectories(dir) if test.error == nil { if err != nil { t.Fatal(err)