@@ -12,7 +12,7 @@ import (
1212 "strings"
1313 "sync"
1414
15- "github.com/ghodss/ yaml"
15+ "gopkg.in/ yaml.v3 "
1616)
1717
1818const rootRegistryPath = "../../../registry"
@@ -23,18 +23,18 @@ type directoryReadme struct {
2323}
2424
2525type rawContributorProfileFrontmatter struct {
26- DisplayName string `yaml:"display_name"`
27- Bio string `yaml:"bio"`
28- GithubUsername string `yaml:"github"`
29- AvatarUrl * string `yaml:"avatar"`
30- LinkedinURL * string `yaml:"linkedin"`
31- WebsiteURL * string `yaml:"website"`
32- SupportEmail * string `yaml:"support_email"`
33- CompanyGithub * string `yaml:"company_github "`
34- ContributorStatus * string `yaml:"status"`
26+ DisplayName string `yaml:"display_name"`
27+ Bio string `yaml:"bio"`
28+ GithubUsername string `yaml:"github"`
29+ AvatarUrl * string `yaml:"avatar"`
30+ LinkedinURL * string `yaml:"linkedin"`
31+ WebsiteURL * string `yaml:"website"`
32+ SupportEmail * string `yaml:"support_email"`
33+ EmployerGithubUsername * string `yaml:"employer_github "`
34+ ContributorStatus * string `yaml:"status"`
3535}
3636
37- type trackableContributorFrontmatter struct {
37+ type contributorFrontmatterWithFilepath struct {
3838 rawContributorProfileFrontmatter
3939 FilePath string
4040}
@@ -97,7 +97,7 @@ func extractFrontmatter(readmeText string) (string, error) {
9797 }
9898
9999 if nextLine != fence {
100- fm += nextLine
100+ fm += nextLine + " \n "
101101 continue
102102 }
103103
@@ -113,7 +113,7 @@ func extractFrontmatter(readmeText string) (string, error) {
113113 return fm , nil
114114}
115115
116- func validateContributorYaml (yml trackableContributorFrontmatter ) []error {
116+ func validateContributorYaml (yml contributorFrontmatterWithFilepath ) []error {
117117 // This function needs to aggregate a bunch of different errors, rather than
118118 // stopping at the first one found, so using code blocks to section off
119119 // logic for different fields
@@ -145,8 +145,8 @@ func validateContributorYaml(yml trackableContributorFrontmatter) []error {
145145 }
146146
147147 // Company GitHub
148- if yml .CompanyGithub != nil {
149- if * yml .CompanyGithub == "" {
148+ if yml .EmployerGithubUsername != nil {
149+ if * yml .EmployerGithubUsername == "" {
150150 errors = append (
151151 errors ,
152152 fmt .Errorf (
@@ -156,19 +156,19 @@ func validateContributorYaml(yml trackableContributorFrontmatter) []error {
156156 )
157157 }
158158
159- lower := strings .ToLower (* yml .CompanyGithub )
159+ lower := strings .ToLower (* yml .EmployerGithubUsername )
160160 if uriSafe := url .PathEscape (lower ); uriSafe != lower {
161161 errors = append (
162162 errors ,
163163 fmt .Errorf (
164164 "gitHub company username %q (%q) is not a valid URL path segment" ,
165- * yml .CompanyGithub ,
165+ * yml .EmployerGithubUsername ,
166166 yml .FilePath ,
167167 ),
168168 )
169169 }
170170
171- if * yml .CompanyGithub == yml .GithubUsername {
171+ if * yml .EmployerGithubUsername == yml .GithubUsername {
172172 errors = append (
173173 errors ,
174174 fmt .Errorf (
@@ -315,7 +315,7 @@ website:
315315}
316316
317317func remapContributorProfile (
318- frontmatter trackableContributorFrontmatter ,
318+ frontmatter contributorFrontmatterWithFilepath ,
319319 employeeGitHubNames []string ,
320320) contributorProfile {
321321 // Function assumes that fields are previously validated and are safe to
@@ -354,20 +354,20 @@ func remapContributorProfile(
354354 return remapped
355355}
356356
357- func parseContributorFiles (input []directoryReadme ) (
357+ func parseContributorFiles (readmeEntries []directoryReadme ) (
358358 map [string ]contributorProfile ,
359359 error ,
360360) {
361- frontmatterByGithub := map [string ]trackableContributorFrontmatter {}
361+ frontmatterByGithub := map [string ]contributorFrontmatterWithFilepath {}
362362 yamlParsingErrors := workflowPhaseError {
363363 Phase : "YAML parsing" ,
364364 }
365- for _ , dirReadme := range input {
366- fmText , err := extractFrontmatter (dirReadme .RawText )
365+ for _ , rm := range readmeEntries {
366+ fmText , err := extractFrontmatter (rm .RawText )
367367 if err != nil {
368368 yamlParsingErrors .Errors = append (
369369 yamlParsingErrors .Errors ,
370- fmt .Errorf ("failed to parse %q: %v" , dirReadme .FilePath , err ),
370+ fmt .Errorf ("failed to parse %q: %v" , rm .FilePath , err ),
371371 )
372372 continue
373373 }
@@ -376,12 +376,13 @@ func parseContributorFiles(input []directoryReadme) (
376376 if err := yaml .Unmarshal ([]byte (fmText ), & yml ); err != nil {
377377 yamlParsingErrors .Errors = append (
378378 yamlParsingErrors .Errors ,
379- fmt .Errorf ("failed to parse %q: %v" , dirReadme .FilePath , err ),
379+ fmt .Errorf ("failed to parse %q: %v" , rm .FilePath , err ),
380380 )
381381 continue
382382 }
383- trackable := trackableContributorFrontmatter {
384- FilePath : dirReadme .FilePath ,
383+
384+ trackable := contributorFrontmatterWithFilepath {
385+ FilePath : rm .FilePath ,
385386 rawContributorProfileFrontmatter : yml ,
386387 }
387388
@@ -391,15 +392,18 @@ func parseContributorFiles(input []directoryReadme) (
391392 fmt .Errorf (
392393 "GitHub name conflict for %q for files %q and %q" ,
393394 trackable .GithubUsername ,
394- trackable .FilePath ,
395395 prev .FilePath ,
396+ trackable .FilePath ,
396397 ),
397398 )
398399 continue
399400 }
400401
401402 frontmatterByGithub [trackable .GithubUsername ] = trackable
402403 }
404+ if len (yamlParsingErrors .Errors ) != 0 {
405+ return nil , yamlParsingErrors
406+ }
403407
404408 employeeGithubGroups := map [string ][]string {}
405409 yamlValidationErrors := workflowPhaseError {
@@ -415,9 +419,9 @@ func parseContributorFiles(input []directoryReadme) (
415419 continue
416420 }
417421
418- if yml .CompanyGithub != nil {
419- employeeGithubGroups [* yml .CompanyGithub ] = append (
420- employeeGithubGroups [* yml .CompanyGithub ],
422+ if yml .EmployerGithubUsername != nil {
423+ employeeGithubGroups [* yml .EmployerGithubUsername ] = append (
424+ employeeGithubGroups [* yml .EmployerGithubUsername ],
421425 yml .GithubUsername ,
422426 )
423427 }
@@ -443,8 +447,8 @@ func parseContributorFiles(input []directoryReadme) (
443447 contributorError .Errors ,
444448 fmt .Errorf (
445449 "company %q does not exist in %q directory but is referenced by these profiles: [%s]" ,
446- rootRegistryPath ,
447450 companyName ,
451+ rootRegistryPath ,
448452 strings .Join (group , ", " ),
449453 ),
450454 )
0 commit comments