@@ -12,7 +12,7 @@ import (
12
12
"strings"
13
13
"sync"
14
14
15
- "github.com/ghodss/ yaml"
15
+ "gopkg.in/ yaml.v3 "
16
16
)
17
17
18
18
const rootRegistryPath = "../../../registry"
@@ -23,18 +23,18 @@ type directoryReadme struct {
23
23
}
24
24
25
25
type 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"`
35
35
}
36
36
37
- type trackableContributorFrontmatter struct {
37
+ type contributorFrontmatterWithFilepath struct {
38
38
rawContributorProfileFrontmatter
39
39
FilePath string
40
40
}
@@ -97,7 +97,7 @@ func extractFrontmatter(readmeText string) (string, error) {
97
97
}
98
98
99
99
if nextLine != fence {
100
- fm += nextLine
100
+ fm += nextLine + " \n "
101
101
continue
102
102
}
103
103
@@ -113,7 +113,7 @@ func extractFrontmatter(readmeText string) (string, error) {
113
113
return fm , nil
114
114
}
115
115
116
- func validateContributorYaml (yml trackableContributorFrontmatter ) []error {
116
+ func validateContributorYaml (yml contributorFrontmatterWithFilepath ) []error {
117
117
// This function needs to aggregate a bunch of different errors, rather than
118
118
// stopping at the first one found, so using code blocks to section off
119
119
// logic for different fields
@@ -145,8 +145,8 @@ func validateContributorYaml(yml trackableContributorFrontmatter) []error {
145
145
}
146
146
147
147
// Company GitHub
148
- if yml .CompanyGithub != nil {
149
- if * yml .CompanyGithub == "" {
148
+ if yml .EmployerGithubUsername != nil {
149
+ if * yml .EmployerGithubUsername == "" {
150
150
errors = append (
151
151
errors ,
152
152
fmt .Errorf (
@@ -156,19 +156,19 @@ func validateContributorYaml(yml trackableContributorFrontmatter) []error {
156
156
)
157
157
}
158
158
159
- lower := strings .ToLower (* yml .CompanyGithub )
159
+ lower := strings .ToLower (* yml .EmployerGithubUsername )
160
160
if uriSafe := url .PathEscape (lower ); uriSafe != lower {
161
161
errors = append (
162
162
errors ,
163
163
fmt .Errorf (
164
164
"gitHub company username %q (%q) is not a valid URL path segment" ,
165
- * yml .CompanyGithub ,
165
+ * yml .EmployerGithubUsername ,
166
166
yml .FilePath ,
167
167
),
168
168
)
169
169
}
170
170
171
- if * yml .CompanyGithub == yml .GithubUsername {
171
+ if * yml .EmployerGithubUsername == yml .GithubUsername {
172
172
errors = append (
173
173
errors ,
174
174
fmt .Errorf (
@@ -315,7 +315,7 @@ website:
315
315
}
316
316
317
317
func remapContributorProfile (
318
- frontmatter trackableContributorFrontmatter ,
318
+ frontmatter contributorFrontmatterWithFilepath ,
319
319
employeeGitHubNames []string ,
320
320
) contributorProfile {
321
321
// Function assumes that fields are previously validated and are safe to
@@ -354,20 +354,20 @@ func remapContributorProfile(
354
354
return remapped
355
355
}
356
356
357
- func parseContributorFiles (input []directoryReadme ) (
357
+ func parseContributorFiles (readmeEntries []directoryReadme ) (
358
358
map [string ]contributorProfile ,
359
359
error ,
360
360
) {
361
- frontmatterByGithub := map [string ]trackableContributorFrontmatter {}
361
+ frontmatterByGithub := map [string ]contributorFrontmatterWithFilepath {}
362
362
yamlParsingErrors := workflowPhaseError {
363
363
Phase : "YAML parsing" ,
364
364
}
365
- for _ , dirReadme := range input {
366
- fmText , err := extractFrontmatter (dirReadme .RawText )
365
+ for _ , rm := range readmeEntries {
366
+ fmText , err := extractFrontmatter (rm .RawText )
367
367
if err != nil {
368
368
yamlParsingErrors .Errors = append (
369
369
yamlParsingErrors .Errors ,
370
- fmt .Errorf ("failed to parse %q: %v" , dirReadme .FilePath , err ),
370
+ fmt .Errorf ("failed to parse %q: %v" , rm .FilePath , err ),
371
371
)
372
372
continue
373
373
}
@@ -376,12 +376,13 @@ func parseContributorFiles(input []directoryReadme) (
376
376
if err := yaml .Unmarshal ([]byte (fmText ), & yml ); err != nil {
377
377
yamlParsingErrors .Errors = append (
378
378
yamlParsingErrors .Errors ,
379
- fmt .Errorf ("failed to parse %q: %v" , dirReadme .FilePath , err ),
379
+ fmt .Errorf ("failed to parse %q: %v" , rm .FilePath , err ),
380
380
)
381
381
continue
382
382
}
383
- trackable := trackableContributorFrontmatter {
384
- FilePath : dirReadme .FilePath ,
383
+
384
+ trackable := contributorFrontmatterWithFilepath {
385
+ FilePath : rm .FilePath ,
385
386
rawContributorProfileFrontmatter : yml ,
386
387
}
387
388
@@ -391,15 +392,18 @@ func parseContributorFiles(input []directoryReadme) (
391
392
fmt .Errorf (
392
393
"GitHub name conflict for %q for files %q and %q" ,
393
394
trackable .GithubUsername ,
394
- trackable .FilePath ,
395
395
prev .FilePath ,
396
+ trackable .FilePath ,
396
397
),
397
398
)
398
399
continue
399
400
}
400
401
401
402
frontmatterByGithub [trackable .GithubUsername ] = trackable
402
403
}
404
+ if len (yamlParsingErrors .Errors ) != 0 {
405
+ return nil , yamlParsingErrors
406
+ }
403
407
404
408
employeeGithubGroups := map [string ][]string {}
405
409
yamlValidationErrors := workflowPhaseError {
@@ -415,9 +419,9 @@ func parseContributorFiles(input []directoryReadme) (
415
419
continue
416
420
}
417
421
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 ],
421
425
yml .GithubUsername ,
422
426
)
423
427
}
@@ -443,8 +447,8 @@ func parseContributorFiles(input []directoryReadme) (
443
447
contributorError .Errors ,
444
448
fmt .Errorf (
445
449
"company %q does not exist in %q directory but is referenced by these profiles: [%s]" ,
446
- rootRegistryPath ,
447
450
companyName ,
451
+ rootRegistryPath ,
448
452
strings .Join (group , ", " ),
449
453
),
450
454
)
0 commit comments