Skip to content

Commit d4d3074

Browse files
Merge pull request #18 from coder/mes/tighten-schema
chore: update README files and validation to reflect new requirements
2 parents 31c69e2 + 7e8d4b7 commit d4d3074

File tree

4 files changed

+16
-88
lines changed

4 files changed

+16
-88
lines changed

cmd/readmevalidation/contributors.go

Lines changed: 15 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,23 @@ import (
1616
var validContributorStatuses = []string{"official", "partner", "community"}
1717

1818
type contributorProfileFrontmatter struct {
19-
DisplayName string `yaml:"display_name"`
20-
Bio string `yaml:"bio"`
21-
GithubUsername string `yaml:"github"`
19+
DisplayName string `yaml:"display_name"`
20+
Bio string `yaml:"bio"`
2221
// Script assumes that if value is nil, the Registry site build step will
2322
// backfill the value with the user's GitHub avatar URL
24-
AvatarURL *string `yaml:"avatar"`
25-
LinkedinURL *string `yaml:"linkedin"`
26-
WebsiteURL *string `yaml:"website"`
27-
SupportEmail *string `yaml:"support_email"`
28-
EmployerGithubUsername *string `yaml:"employer_github"`
29-
ContributorStatus *string `yaml:"status"`
23+
AvatarURL *string `yaml:"avatar"`
24+
LinkedinURL *string `yaml:"linkedin"`
25+
WebsiteURL *string `yaml:"website"`
26+
SupportEmail *string `yaml:"support_email"`
27+
ContributorStatus *string `yaml:"status"`
3028
}
3129

3230
type contributorProfile struct {
3331
frontmatter contributorProfileFrontmatter
32+
namespace string
3433
filePath string
3534
}
3635

37-
func validateContributorGithubUsername(githubUsername string) error {
38-
if githubUsername == "" {
39-
return errors.New("missing GitHub username")
40-
}
41-
42-
lower := strings.ToLower(githubUsername)
43-
if uriSafe := url.PathEscape(lower); uriSafe != lower {
44-
return fmt.Errorf("gitHub username %q is not a valid URL path segment", githubUsername)
45-
}
46-
47-
return nil
48-
}
49-
50-
func validateContributorEmployerGithubUsername(employerGithubUsername *string, githubUsername string) []error {
51-
if employerGithubUsername == nil {
52-
return nil
53-
}
54-
55-
errs := []error{}
56-
if *employerGithubUsername == "" {
57-
errs = append(errs, errors.New("company_github field is defined but has empty value"))
58-
return errs
59-
}
60-
61-
lower := strings.ToLower(*employerGithubUsername)
62-
if uriSafe := url.PathEscape(lower); uriSafe != lower {
63-
errs = append(errs, fmt.Errorf("gitHub company username %q is not a valid URL path segment", *employerGithubUsername))
64-
}
65-
66-
if *employerGithubUsername == githubUsername {
67-
errs = append(errs, fmt.Errorf("cannot list own GitHub name (%q) as employer", githubUsername))
68-
}
69-
70-
return errs
71-
}
72-
7336
func validateContributorDisplayName(displayName string) error {
7437
if displayName == "" {
7538
return fmt.Errorf("missing display_name")
@@ -195,9 +158,6 @@ func validateContributorAvatarURL(avatarURL *string) []error {
195158
func validateContributorYaml(yml contributorProfile) []error {
196159
allErrs := []error{}
197160

198-
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
199-
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
200-
}
201161
if err := validateContributorDisplayName(yml.frontmatter.DisplayName); err != nil {
202162
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
203163
}
@@ -211,9 +171,6 @@ func validateContributorYaml(yml contributorProfile) []error {
211171
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
212172
}
213173

214-
for _, err := range validateContributorEmployerGithubUsername(yml.frontmatter.EmployerGithubUsername, yml.frontmatter.GithubUsername) {
215-
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
216-
}
217174
for _, err := range validateContributorSupportEmail(yml.frontmatter.SupportEmail) {
218175
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
219176
}
@@ -238,11 +195,12 @@ func parseContributorProfile(rm readme) (contributorProfile, error) {
238195
return contributorProfile{
239196
filePath: rm.filePath,
240197
frontmatter: yml,
198+
namespace: strings.TrimSuffix(strings.TrimPrefix(rm.filePath, "registry/"), "/README.md"),
241199
}, nil
242200
}
243201

244202
func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfile, error) {
245-
profilesByUsername := map[string]contributorProfile{}
203+
profilesByNamespace := map[string]contributorProfile{}
246204
yamlParsingErrors := []error{}
247205
for _, rm := range readmeEntries {
248206
p, err := parseContributorProfile(rm)
@@ -251,11 +209,11 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
251209
continue
252210
}
253211

254-
if prev, alreadyExists := profilesByUsername[p.frontmatter.GithubUsername]; alreadyExists {
255-
yamlParsingErrors = append(yamlParsingErrors, fmt.Errorf("%q: GitHub name %s conflicts with field defined in %q", p.filePath, p.frontmatter.GithubUsername, prev.filePath))
212+
if prev, alreadyExists := profilesByNamespace[p.namespace]; alreadyExists {
213+
yamlParsingErrors = append(yamlParsingErrors, fmt.Errorf("%q: namespace %q conflicts with namespace from %q", p.filePath, p.namespace, prev.filePath))
256214
continue
257215
}
258-
profilesByUsername[p.frontmatter.GithubUsername] = p
216+
profilesByNamespace[p.namespace] = p
259217
}
260218
if len(yamlParsingErrors) != 0 {
261219
return nil, validationPhaseError{
@@ -264,27 +222,13 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
264222
}
265223
}
266224

267-
employeeGithubGroups := map[string][]string{}
268225
yamlValidationErrors := []error{}
269-
for _, p := range profilesByUsername {
226+
for _, p := range profilesByNamespace {
270227
errors := validateContributorYaml(p)
271228
if len(errors) > 0 {
272229
yamlValidationErrors = append(yamlValidationErrors, errors...)
273230
continue
274231
}
275-
276-
if p.frontmatter.EmployerGithubUsername != nil {
277-
employeeGithubGroups[*p.frontmatter.EmployerGithubUsername] = append(
278-
employeeGithubGroups[*p.frontmatter.EmployerGithubUsername],
279-
p.frontmatter.GithubUsername,
280-
)
281-
}
282-
}
283-
for companyName, group := range employeeGithubGroups {
284-
if _, found := profilesByUsername[companyName]; found {
285-
continue
286-
}
287-
yamlValidationErrors = append(yamlValidationErrors, fmt.Errorf("%q: company %q does not exist but is referenced by these profiles: [%s]", rootRegistryPath, companyName, strings.Join(group, ", ")))
288232
}
289233
if len(yamlValidationErrors) != 0 {
290234
return nil, validationPhaseError{
@@ -293,7 +237,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
293237
}
294238
}
295239

296-
return profilesByUsername, nil
240+
return profilesByNamespace, nil
297241
}
298242

299243
func aggregateContributorReadmeFiles() ([]readme, error) {

registry/hashicorp/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

registry/jfrog/README.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

registry/nataindata/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ display_name: Nataindata
33
bio: Data engineer
44
github: nataindata
55
website: https://www.nataindata.com
6-
status: community
6+
status: partner
77
---

0 commit comments

Comments
 (0)