Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

populate-owners: Also populate ci-operator/templates/{org}/{repo} #1769

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tools/populate-owners/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions tools/populate-owners/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions tools/populate-owners/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down