Skip to content

Commit

Permalink
Merge pull request #1769 from wking/populate-owners-templates
Browse files Browse the repository at this point in the history
populate-owners: Also populate ci-operator/templates/{org}/{repo}
  • Loading branch information
openshift-merge-robot committed Oct 2, 2018
2 parents 7d9f9bd + ed1f852 commit ed41bd8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
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

0 comments on commit ed41bd8

Please sign in to comment.