Skip to content

Commit 206dc9e

Browse files
committed
tools/populate-owners: Also populate ci-operator/config/{org}/{repo}/OWNERS
The old shell script used to do this, but I'd accidentally dropped the functionality in e1f993f (populate-owners: Also slurp OWNERS_ALIASES, 2018-08-25, openshift#1285).
1 parent 8f42984 commit 206dc9e

File tree

3 files changed

+85
-3
lines changed

3 files changed

+85
-3
lines changed

tools/populate-owners/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ For example, if [openshift/origin][] and [openshift/installer][] both defined an
2323
After namespacing aliases, the utility writes `OWNERS_ALIASES` to the root of this repository.
2424
If no upstreams define aliases, then the utility removes `OWNER_ALIASES` from the root of this repository.
2525

26-
The utility also iterates through the `ci-operator/jobs/{organization}/{repository}` directories, writing `OWNERS` to reflect the upstream configuration.
27-
If the upstream did not have an `OWNERS` file, the utility removes the associated `ci-operator/jobs/{organization}/{repository}/OWNERS`.
26+
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.
27+
If the upstream did not have an `OWNERS` file, the utility removes the associated `ci-operator/*/{organization}/{repository}/OWNERS`.
2828

2929
[openshift/origin]: https://github.com/openshift/origin
3030
[openshift/installer]: https://github.com/openshift/installer

tools/populate-owners/main.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,20 @@ func orgRepos(dir string) (orgRepos []*orgRepo, err error) {
9393
return orgRepos, err
9494
}
9595

96+
func (orgRepo *orgRepo) getConfig(dir string) (err error) {
97+
path := filepath.Join(dir, orgRepo.Organization, orgRepo.Repository)
98+
info, err := os.Stat(path)
99+
if err != nil {
100+
return err
101+
}
102+
103+
if info.IsDir() {
104+
orgRepo.Directories = append(orgRepo.Directories, path)
105+
}
106+
107+
return nil
108+
}
109+
96110
func (orgRepo *orgRepo) getOwners() (err error) {
97111
dir, err := ioutil.TempDir("", "populate-owners-")
98112
if err != nil {
@@ -296,8 +310,14 @@ func pullOwners(directory string) (err error) {
296310
return err
297311
}
298312

313+
config := filepath.Join(repoRoot, "ci-operator", "config")
299314
for _, orgRepo := range orgRepos {
300-
err := orgRepo.getOwners()
315+
err = orgRepo.getConfig(config)
316+
if err != nil && !os.IsNotExist(err) {
317+
return err
318+
}
319+
320+
err = orgRepo.getOwners()
301321
if err != nil && !os.IsNotExist(err) {
302322
return err
303323
}

tools/populate-owners/main_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,68 @@ func TestOrgRepos(t *testing.T) {
9292
assertEqual(t, orgRepos, expected)
9393
}
9494

95+
func TestGetConfig(t *testing.T) {
96+
dir, err := ioutil.TempDir("", "populate-owners-")
97+
if err != nil {
98+
t.Fatal(err)
99+
}
100+
defer os.RemoveAll(dir)
101+
102+
repoAB := filepath.Join(dir, "a", "b")
103+
err = os.MkdirAll(repoAB, 0777)
104+
if err != nil {
105+
t.Fatal(err)
106+
}
107+
108+
for _, test := range []struct{
109+
name string
110+
input *orgRepo
111+
expected *orgRepo
112+
error *regexp.Regexp
113+
}{
114+
{
115+
name: "config exists",
116+
input: &orgRepo{
117+
Directories: []string{"some/directory"},
118+
Organization: "a",
119+
Repository: "b",
120+
},
121+
expected: &orgRepo{
122+
Directories: []string{"some/directory", filepath.Join(dir, "a", "b")},
123+
Organization: "a",
124+
Repository: "b",
125+
},
126+
},
127+
{
128+
name: "config does not exist",
129+
input: &orgRepo{
130+
Directories: []string{"some/directory"},
131+
Organization: "c",
132+
Repository: "d",
133+
},
134+
expected: &orgRepo{
135+
Directories: []string{"some/directory"},
136+
Organization: "c",
137+
Repository: "d",
138+
},
139+
error: regexp.MustCompile("^stat .*/c/d: no such file or directory"),
140+
},
141+
} {
142+
t.Run(test.name, func (t *testing.T) {
143+
err := test.input.getConfig(dir)
144+
if test.error == nil {
145+
if err != nil {
146+
t.Fatal(err)
147+
}
148+
} else if !test.error.MatchString(err.Error()) {
149+
t.Fatalf("unexpected error: %v does not match %v", err, test.error)
150+
}
151+
152+
assertEqual(t, test.input, test.expected)
153+
})
154+
}
155+
}
156+
95157
func TestExtractOwners(t *testing.T) {
96158
dir, err := ioutil.TempDir("", "populate-owners-")
97159
if err != nil {

0 commit comments

Comments
 (0)