From 320c5f10d6495cbdeb8b87ab9e8acd1b140db226 Mon Sep 17 00:00:00 2001 From: Aaron Crickenberger Date: Mon, 8 Mar 2021 00:19:15 -0500 Subject: [PATCH] generator: add validation of subprojects specifically: - only sigs+committees can have subprojects - subprojects need at least one owners entry - owners should be raw github links I think the last one could/should change, but: - I'm about to auto-generate links assuming this format, so I want to verify I can assume all owners are in this format - I am not quite sure if we should treat sigs.yaml as public api and give notice/deprecation for field changes --- generator/app.go | 16 ++++++++++++++++ generator/testdata/sigs.yaml | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/generator/app.go b/generator/app.go index 3618f4dce..e48a123b0 100644 --- a/generator/app.go +++ b/generator/app.go @@ -246,6 +246,7 @@ func (c *Context) Sort() { func (c *Context) Validate() []error { errors := []error{} people := make(map[string]Person) + rawGitHubURL := regexp.MustCompile(regexRawGitHubURL) for prefix, groups := range c.PrefixToGroupMap() { for _, group := range groups { expectedDir := group.DirName(prefix) @@ -294,6 +295,21 @@ func (c *Context) Validate() []error { errors = append(errors, fmt.Errorf("%s: has no subprojects", group.Dir)) } } + if prefix != "committee" && prefix != "sig" { + if len(group.Subprojects) > 0 { + errors = append(errors, fmt.Errorf("%s: only sigs and committees can own code / have subprojects, found: %v", group.Dir, group.Subprojects)) + } + } + for _, subproject := range group.Subprojects { + if len(subproject.Owners) == 0 { + errors = append(errors, fmt.Errorf("%s/%s: subproject has no owners", group.Dir, subproject.Name)) + } + for _, ownerURL := range subproject.Owners { + if !rawGitHubURL.MatchString(ownerURL) { + errors = append(errors, fmt.Errorf("%s/%s: subproject owners should match regexp %s, found: %s", group.Dir, subproject.Name, regexRawGitHubURL, ownerURL)) + } + } + } } } return errors diff --git a/generator/testdata/sigs.yaml b/generator/testdata/sigs.yaml index 60474dda9..191982fee 100644 --- a/generator/testdata/sigs.yaml +++ b/generator/testdata/sigs.yaml @@ -6,6 +6,8 @@ sigs: mission_statement: covers foo subprojects: - name: sub-foo + owners: + - "https://raw.githubusercontent.com/org/foo/main/OWNERS" - dir: sig-bar name: Bar label: bar @@ -13,6 +15,8 @@ sigs: mission_statement: owns areas related to bar subprojects: - name: sub-bar + owners: + - "https://raw.githubusercontent.com/org/bar/main/test/OWNERS" workinggroups: - dir: wg-baz name: Baz