diff --git a/validators/cmd/sigs/sigs-validator.go b/validators/cmd/sigs/sigs-validator.go index fdf043de..d6dc3e48 100644 --- a/validators/cmd/sigs/sigs-validator.go +++ b/validators/cmd/sigs/sigs-validator.go @@ -100,20 +100,17 @@ func main() { } func validateGroups(sigsYAML *sigs.Sigs, labelsYAML *labels.LabelsYAML, kubevirtOrg orgs.Org) { - for _, sig := range sigsYAML.Sigs { - validateGroup("sig", sig, labelsYAML, kubevirtOrg) + groupsToValidate := map[string][]*sigs.Group{ + "sig": sigsYAML.Sigs, + "wg": sigsYAML.Workinggroups, + "ug": sigsYAML.Usergroups, + "committee": sigsYAML.Committees, } - for _, wg := range sigsYAML.Workinggroups { - validateGroup("wg", wg, labelsYAML, kubevirtOrg) - } - - for _, ug := range sigsYAML.Usergroups { - validateGroup("ug", ug, labelsYAML, kubevirtOrg) - } - - for _, committee := range sigsYAML.Committees { - validateGroup("committee", committee, labelsYAML, kubevirtOrg) + for groupType, groups := range groupsToValidate { + for _, group := range groups { + validateGroup(groupType, group, labelsYAML, kubevirtOrg) + } } } @@ -121,85 +118,84 @@ func validateGroup(groupType string, groupToValidate *sigs.Group, labelsYAML *la groupLog := log.WithField(groupType, groupToValidate.Name) validateDirectoryExists(groupToValidate, groupLog) validateLabelExists(groupToValidate, labelsYAML, groupLog) - validateLeads(groupToValidate, kubevirtOrg, groupLog) + validateGroupLeads(groupToValidate, kubevirtOrg, groupLog) validateChairs(groupToValidate, kubevirtOrg, groupLog) validateSubprojects(groupToValidate, groupLog, kubevirtOrg) } func validateDirectoryExists(groupToValidate *sigs.Group, groupLog *log.Entry) { - if groupToValidate.Dir != "" { - stat, err := os.Stat(groupToValidate.Dir) - if err != nil { - groupLog.Errorf("dir %q not found: %v", groupToValidate.Dir, err) - groupToValidate.Dir = "" - } else if !stat.IsDir() { - groupLog.Errorf("dir %q is not a directory", groupToValidate.Dir) - groupToValidate.Dir = "" - } + if groupToValidate.Dir == "" { + return + } + + stat, err := os.Stat(groupToValidate.Dir) + if err != nil { + groupLog.Errorf("dir %q not found: %v", groupToValidate.Dir, err) + groupToValidate.Dir = "" + } else if !stat.IsDir() { + groupLog.Errorf("dir %q is not a directory", groupToValidate.Dir) + groupToValidate.Dir = "" } } func validateLabelExists(groupToValidate *sigs.Group, labelsYAML *labels.LabelsYAML, groupLog *log.Entry) { - if groupToValidate.Label != "" { - foundLabel := false - for _, label := range labelsYAML.Default.Labels { - if label.Name == groupToValidate.Label { - foundLabel = true - break - } - } - if !foundLabel { - groupLog.Errorf("label %q not found", groupToValidate.Label) - groupToValidate.Label = "" - } + if groupToValidate.Label == "" { + return } -} -// validateLeads checks that leads github handles are part of org, removes all that don't satisfy this requirement -func validateLeads(groupToValidate *sigs.Group, kubevirtOrg orgs.Org, groupLog *log.Entry) { - var checkedMembers []*sigs.Lead - for _, orgMember := range groupToValidate.Leads { - if !kubevirtOrg.HasMember(orgMember.Github) { - groupLog.Errorf("lead %q not found", orgMember) - } else { - checkedMembers = append(checkedMembers, orgMember) + foundLabel := false + for _, label := range labelsYAML.Default.Labels { + if label.Name == groupToValidate.Label { + foundLabel = true + break } } - groupToValidate.Leads = checkedMembers + if !foundLabel { + groupLog.Errorf("label %q not found", groupToValidate.Label) + groupToValidate.Label = "" + } +} + +// validateGroupLeads checks that leads github handles are part of org, removes all that don't satisfy this requirement +func validateGroupLeads(groupToValidate *sigs.Group, kubevirtOrg orgs.Org, groupLog *log.Entry) { + groupToValidate.Leads = validateLeads(groupToValidate.Leads, kubevirtOrg, groupLog) } -// validateLeads checks that chairs github handles are part of org, removes all that don't satisfy this +// validateChairs checks that chairs github handles are part of org, removes all that don't satisfy this func validateChairs(groupToValidate *sigs.Group, kubevirtOrg orgs.Org, groupLog *log.Entry) { - if groupToValidate.Leadership != nil { - var checkedLeadership []*sigs.Chair - for _, orgMember := range groupToValidate.Leadership.Chairs { - if !kubevirtOrg.HasMember(orgMember.Github) { - groupLog.Errorf("leadership chair %q not found", orgMember) - } else { - checkedLeadership = append(checkedLeadership, orgMember) - } + if groupToValidate.Leadership == nil { + return + } + + var validChairs []*sigs.Chair + for _, orgMember := range groupToValidate.Leadership.Chairs { + if !kubevirtOrg.HasMember(orgMember.Github) { + groupLog.Errorf("leadership chair %q not found", orgMember) + } else { + validChairs = append(validChairs, orgMember) } - groupToValidate.Leadership.Chairs = checkedLeadership } + groupToValidate.Leadership.Chairs = validChairs } func validateSubprojects(groupToValidate *sigs.Group, groupLog *log.Entry, kubevirtOrg orgs.Org) { for _, subProject := range groupToValidate.SubProjects { subprojectLog := groupLog.WithField("subproject", subProject.Name) - foundOwners := validateOwnersReferences(subProject, subprojectLog) - subProject.Owners = foundOwners - - // check subproject leads - github handles are part of org - var checkedSubprojectChairs []*sigs.Lead - for _, orgMember := range subProject.Leads { - if !kubevirtOrg.HasMember(orgMember.Github) { - subprojectLog.Errorf("lead %q not found", orgMember) - } else { - checkedSubprojectChairs = append(checkedSubprojectChairs, orgMember) - } + subProject.Owners = validateOwnersReferences(subProject, subprojectLog) + subProject.Leads = validateLeads(subProject.Leads, kubevirtOrg, groupLog) + } +} + +func validateLeads(leadsToValidate []*sigs.Lead, kubevirtOrg orgs.Org, groupLog *log.Entry) []*sigs.Lead { + var validLeads []*sigs.Lead + for _, orgMember := range leadsToValidate { + if !kubevirtOrg.HasMember(orgMember.Github) { + groupLog.Errorf("lead %q not found", orgMember) + } else { + validLeads = append(validLeads, orgMember) } - subProject.Leads = checkedSubprojectChairs } + return validLeads } func validateOwnersReferences(subProject *sigs.SubProject, subprojectLog *log.Entry) []string {