@@ -45,9 +45,9 @@ type contributorProfileFrontmatter struct {
4545 ContributorStatus * string `yaml:"status"`
4646}
4747
48- type contributorFrontmatterWithFilePath struct {
49- contributorProfileFrontmatter
50- FilePath string
48+ type contributorProfile struct {
49+ frontmatter contributorProfileFrontmatter
50+ filePath string
5151}
5252
5353var _ error = validationPhaseError {}
@@ -266,76 +266,73 @@ func validateContributorAvatarURL(avatarURL *string) []error {
266266 return problems
267267}
268268
269- func validateContributorYaml (yml contributorFrontmatterWithFilePath ) []error {
269+ func validateContributorYaml (yml contributorProfile ) []error {
270270 allProblems := []error {}
271271 addFilePath := func (err error ) error {
272- return fmt .Errorf ("%q: %v" , yml .FilePath , err )
272+ return fmt .Errorf ("%q: %v" , yml .filePath , err )
273273 }
274274
275- if err := validateContributorGithubUsername (yml .GithubUsername ); err != nil {
275+ if err := validateContributorGithubUsername (yml .frontmatter . GithubUsername ); err != nil {
276276 allProblems = append (allProblems , addFilePath (err ))
277277 }
278- if err := validateContributorDisplayName (yml .DisplayName ); err != nil {
278+ if err := validateContributorDisplayName (yml .frontmatter . DisplayName ); err != nil {
279279 allProblems = append (allProblems , addFilePath (err ))
280280 }
281- if err := validateContributorLinkedinURL (yml .LinkedinURL ); err != nil {
281+ if err := validateContributorLinkedinURL (yml .frontmatter . LinkedinURL ); err != nil {
282282 allProblems = append (allProblems , addFilePath (err ))
283283 }
284- if err := validateContributorWebsite (yml .WebsiteURL ); err != nil {
284+ if err := validateContributorWebsite (yml .frontmatter . WebsiteURL ); err != nil {
285285 allProblems = append (allProblems , addFilePath (err ))
286286 }
287- if err := validateContributorStatus (yml .ContributorStatus ); err != nil {
287+ if err := validateContributorStatus (yml .frontmatter . ContributorStatus ); err != nil {
288288 allProblems = append (allProblems , addFilePath (err ))
289289 }
290290
291- for _ , err := range validateContributorEmployerGithubUsername (yml .EmployerGithubUsername , yml .GithubUsername ) {
291+ for _ , err := range validateContributorEmployerGithubUsername (yml .frontmatter . EmployerGithubUsername , yml . frontmatter .GithubUsername ) {
292292 allProblems = append (allProblems , addFilePath (err ))
293293 }
294- for _ , err := range validateContributorSupportEmail (yml .SupportEmail ) {
294+ for _ , err := range validateContributorSupportEmail (yml .frontmatter . SupportEmail ) {
295295 allProblems = append (allProblems , addFilePath (err ))
296296 }
297- for _ , err := range validateContributorAvatarURL (yml .AvatarURL ) {
297+ for _ , err := range validateContributorAvatarURL (yml .frontmatter . AvatarURL ) {
298298 allProblems = append (allProblems , addFilePath (err ))
299299 }
300300
301301 return allProblems
302302}
303303
304- func parseContributor (rm readme ) (contributorFrontmatterWithFilePath , error ) {
304+ func parseContributorProfile (rm readme ) (contributorProfile , error ) {
305305 fm , err := extractFrontmatter (rm .rawText )
306306 if err != nil {
307- return contributorFrontmatterWithFilePath {}, fmt .Errorf ("%q: failed to parse frontmatter: %v" , rm .filePath , err )
307+ return contributorProfile {}, fmt .Errorf ("%q: failed to parse frontmatter: %v" , rm .filePath , err )
308308 }
309309
310310 yml := contributorProfileFrontmatter {}
311311 if err := yaml .Unmarshal ([]byte (fm ), & yml ); err != nil {
312- return contributorFrontmatterWithFilePath {}, fmt .Errorf ("%q: failed to parse: %v" , rm .filePath , err )
312+ return contributorProfile {}, fmt .Errorf ("%q: failed to parse: %v" , rm .filePath , err )
313313 }
314314
315- return contributorFrontmatterWithFilePath {
316- FilePath : rm .filePath ,
317- contributorProfileFrontmatter : yml ,
315+ return contributorProfile {
316+ filePath : rm .filePath ,
317+ frontmatter : yml ,
318318 }, nil
319319}
320320
321- func parseContributorFiles (readmeEntries []readme ) (
322- map [string ]contributorFrontmatterWithFilePath ,
323- error ,
324- ) {
325- frontmatterByUsername := map [string ]contributorFrontmatterWithFilePath {}
321+ func parseContributorFiles (readmeEntries []readme ) (map [string ]contributorProfile , error ) {
322+ profilesByUsername := map [string ]contributorProfile {}
326323 yamlParsingErrors := []error {}
327324 for _ , rm := range readmeEntries {
328- fm , err := parseContributor (rm )
325+ p , err := parseContributorProfile (rm )
329326 if err != nil {
330327 yamlParsingErrors = append (yamlParsingErrors , err )
331328 continue
332329 }
333330
334- if prev , isConflict := frontmatterByUsername [ fm . GithubUsername ]; isConflict {
335- yamlParsingErrors = append (yamlParsingErrors , fmt .Errorf ("%q: GitHub name %s conflicts with field defined in %q" , fm . FilePath , fm . GithubUsername , prev .FilePath ))
331+ if prev , alreadyExists := profilesByUsername [ p . frontmatter . GithubUsername ]; alreadyExists {
332+ yamlParsingErrors = append (yamlParsingErrors , fmt .Errorf ("%q: GitHub name %s conflicts with field defined in %q" , p . filePath , p . frontmatter . GithubUsername , prev .filePath ))
336333 continue
337334 }
338- frontmatterByUsername [ fm . GithubUsername ] = fm
335+ profilesByUsername [ p . frontmatter . GithubUsername ] = p
339336 }
340337 if len (yamlParsingErrors ) != 0 {
341338 return nil , validationPhaseError {
@@ -346,22 +343,22 @@ func parseContributorFiles(readmeEntries []readme) (
346343
347344 employeeGithubGroups := map [string ][]string {}
348345 yamlValidationErrors := []error {}
349- for _ , yml := range frontmatterByUsername {
350- errors := validateContributorYaml (yml )
346+ for _ , p := range profilesByUsername {
347+ errors := validateContributorYaml (p )
351348 if len (errors ) > 0 {
352349 yamlValidationErrors = append (yamlValidationErrors , errors ... )
353350 continue
354351 }
355352
356- if yml .EmployerGithubUsername != nil {
357- employeeGithubGroups [* yml .EmployerGithubUsername ] = append (
358- employeeGithubGroups [* yml .EmployerGithubUsername ],
359- yml .GithubUsername ,
353+ if p . frontmatter .EmployerGithubUsername != nil {
354+ employeeGithubGroups [* p . frontmatter .EmployerGithubUsername ] = append (
355+ employeeGithubGroups [* p . frontmatter .EmployerGithubUsername ],
356+ p . frontmatter .GithubUsername ,
360357 )
361358 }
362359 }
363360 for companyName , group := range employeeGithubGroups {
364- if _ , found := frontmatterByUsername [companyName ]; found {
361+ if _ , found := profilesByUsername [companyName ]; found {
365362 continue
366363 }
367364 yamlValidationErrors = append (yamlValidationErrors , fmt .Errorf ("company %q does not exist in %q directory but is referenced by these profiles: [%s]" , companyName , rootRegistryPath , strings .Join (group , ", " )))
@@ -373,7 +370,7 @@ func parseContributorFiles(readmeEntries []readme) (
373370 }
374371 }
375372
376- return frontmatterByUsername , nil
373+ return profilesByUsername , nil
377374}
378375
379376func aggregateContributorReadmeFiles () ([]readme , error ) {
@@ -414,7 +411,7 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
414411}
415412
416413func validateRelativeUrls (
417- contributors map [string ]contributorFrontmatterWithFilePath ,
414+ contributors map [string ]contributorProfile ,
418415) error {
419416 // This function only validates relative avatar URLs for now, but it can be
420417 // beefed up to validate more in the future
@@ -423,24 +420,24 @@ func validateRelativeUrls(
423420 for _ , con := range contributors {
424421 // If the avatar URL is missing, we'll just assume that the Registry
425422 // site build step will take care of filling in the data properly
426- if con .AvatarURL == nil {
423+ if con .frontmatter . AvatarURL == nil {
427424 continue
428425 }
429- if isRelativeURL := strings .HasPrefix (* con .AvatarURL , "." ) ||
430- strings .HasPrefix (* con .AvatarURL , "/" ); ! isRelativeURL {
426+ if isRelativeURL := strings .HasPrefix (* con .frontmatter . AvatarURL , "." ) ||
427+ strings .HasPrefix (* con .frontmatter . AvatarURL , "/" ); ! isRelativeURL {
431428 continue
432429 }
433430
434- if strings .HasPrefix (* con .AvatarURL , ".." ) {
435- problems = append (problems , fmt .Errorf ("%q: relative avatar URLs cannot be placed outside a user's namespaced directory" , con .FilePath ))
431+ if strings .HasPrefix (* con .frontmatter . AvatarURL , ".." ) {
432+ problems = append (problems , fmt .Errorf ("%q: relative avatar URLs cannot be placed outside a user's namespaced directory" , con .filePath ))
436433 continue
437434 }
438435
439- absolutePath := strings .TrimSuffix (con .FilePath , "README.md" ) +
440- * con .AvatarURL
436+ absolutePath := strings .TrimSuffix (con .filePath , "README.md" ) +
437+ * con .frontmatter . AvatarURL
441438 _ , err := os .ReadFile (absolutePath )
442439 if err != nil {
443- problems = append (problems , fmt .Errorf ("%q: relative avatar path %q does not point to image in file system" , con .FilePath , * con .AvatarURL ))
440+ problems = append (problems , fmt .Errorf ("%q: relative avatar path %q does not point to image in file system" , con .filePath , * con . frontmatter .AvatarURL ))
444441 }
445442 }
446443
0 commit comments