Skip to content

Commit 7e8d4b7

Browse files
committed
fix: make Github field optional
1 parent c731a5c commit 7e8d4b7

File tree

1 file changed

+10
-25
lines changed

1 file changed

+10
-25
lines changed

cmd/readmevalidation/contributors.go

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ 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
2423
AvatarURL *string `yaml:"avatar"`
@@ -30,22 +29,10 @@ type contributorProfileFrontmatter struct {
3029

3130
type contributorProfile struct {
3231
frontmatter contributorProfileFrontmatter
32+
namespace string
3333
filePath string
3434
}
3535

36-
func validateContributorGithubUsername(githubUsername string) error {
37-
if githubUsername == "" {
38-
return errors.New("missing GitHub username")
39-
}
40-
41-
lower := strings.ToLower(githubUsername)
42-
if uriSafe := url.PathEscape(lower); uriSafe != lower {
43-
return fmt.Errorf("gitHub username %q is not a valid URL path segment", githubUsername)
44-
}
45-
46-
return nil
47-
}
48-
4936
func validateContributorDisplayName(displayName string) error {
5037
if displayName == "" {
5138
return fmt.Errorf("missing display_name")
@@ -171,9 +158,6 @@ func validateContributorAvatarURL(avatarURL *string) []error {
171158
func validateContributorYaml(yml contributorProfile) []error {
172159
allErrs := []error{}
173160

174-
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
175-
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
176-
}
177161
if err := validateContributorDisplayName(yml.frontmatter.DisplayName); err != nil {
178162
allErrs = append(allErrs, addFilePathToError(yml.filePath, err))
179163
}
@@ -211,11 +195,12 @@ func parseContributorProfile(rm readme) (contributorProfile, error) {
211195
return contributorProfile{
212196
filePath: rm.filePath,
213197
frontmatter: yml,
198+
namespace: strings.TrimSuffix(strings.TrimPrefix(rm.filePath, "registry/"), "/README.md"),
214199
}, nil
215200
}
216201

217202
func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfile, error) {
218-
profilesByUsername := map[string]contributorProfile{}
203+
profilesByNamespace := map[string]contributorProfile{}
219204
yamlParsingErrors := []error{}
220205
for _, rm := range readmeEntries {
221206
p, err := parseContributorProfile(rm)
@@ -224,11 +209,11 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
224209
continue
225210
}
226211

227-
if prev, alreadyExists := profilesByUsername[p.frontmatter.GithubUsername]; alreadyExists {
228-
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))
229214
continue
230215
}
231-
profilesByUsername[p.frontmatter.GithubUsername] = p
216+
profilesByNamespace[p.namespace] = p
232217
}
233218
if len(yamlParsingErrors) != 0 {
234219
return nil, validationPhaseError{
@@ -238,7 +223,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
238223
}
239224

240225
yamlValidationErrors := []error{}
241-
for _, p := range profilesByUsername {
226+
for _, p := range profilesByNamespace {
242227
errors := validateContributorYaml(p)
243228
if len(errors) > 0 {
244229
yamlValidationErrors = append(yamlValidationErrors, errors...)
@@ -252,7 +237,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
252237
}
253238
}
254239

255-
return profilesByUsername, nil
240+
return profilesByNamespace, nil
256241
}
257242

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

0 commit comments

Comments
 (0)