refactor: split off another function
This commit is contained in:
parent
96fa5d4157
commit
5c45642e4b
@ -298,59 +298,55 @@ func validateContributorYaml(yml contributorFrontmatterWithFilePath) []error {
|
|||||||
return allProblems
|
return allProblems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func parseContributor(rm readme) (contributorFrontmatterWithFilePath, error) {
|
||||||
|
fm, err := extractFrontmatter(rm.RawText)
|
||||||
|
if err != nil {
|
||||||
|
return contributorFrontmatterWithFilePath{}, fmt.Errorf("%q: failed to parse frontmatter: %v", rm.FilePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
yml := contributorProfileFrontmatter{}
|
||||||
|
if err := yaml.Unmarshal([]byte(fm), &yml); err != nil {
|
||||||
|
return contributorFrontmatterWithFilePath{}, fmt.Errorf("%q: failed to parse: %v", rm.FilePath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return contributorFrontmatterWithFilePath{
|
||||||
|
FilePath: rm.FilePath,
|
||||||
|
contributorProfileFrontmatter: yml,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
func parseContributorFiles(readmeEntries []readme) (
|
func parseContributorFiles(readmeEntries []readme) (
|
||||||
map[string]contributorFrontmatterWithFilePath,
|
map[string]contributorFrontmatterWithFilePath,
|
||||||
error,
|
error,
|
||||||
) {
|
) {
|
||||||
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
|
frontmatterByUsername := map[string]contributorFrontmatterWithFilePath{}
|
||||||
yamlParsingErrors := validationPhaseError{
|
yamlParsingErrors := []error{}
|
||||||
Phase: "YAML parsing",
|
|
||||||
}
|
|
||||||
for _, rm := range readmeEntries {
|
for _, rm := range readmeEntries {
|
||||||
fm, err := extractFrontmatter(rm.RawText)
|
fm, err := parseContributor(rm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
yamlParsingErrors.Errors = append(
|
yamlParsingErrors = append(yamlParsingErrors, err)
|
||||||
yamlParsingErrors.Errors,
|
|
||||||
fmt.Errorf("%q: failed to parse: %v", rm.FilePath, err),
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
yml := contributorProfileFrontmatter{}
|
if prev, isConflict := frontmatterByUsername[fm.GithubUsername]; isConflict {
|
||||||
if err := yaml.Unmarshal([]byte(fm), &yml); err != nil {
|
yamlParsingErrors = append(yamlParsingErrors, fmt.Errorf("%q: GitHub name %s conflicts with field defined in %q", fm.FilePath, fm.GithubUsername, prev.FilePath))
|
||||||
yamlParsingErrors.Errors = append(
|
|
||||||
yamlParsingErrors.Errors,
|
|
||||||
fmt.Errorf("%q: failed to parse: %v", rm.FilePath, err),
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
processed := contributorFrontmatterWithFilePath{
|
frontmatterByUsername[fm.GithubUsername] = fm
|
||||||
FilePath: rm.FilePath,
|
|
||||||
contributorProfileFrontmatter: yml,
|
|
||||||
}
|
|
||||||
|
|
||||||
if prev, isConflict := frontmatterByUsername[processed.GithubUsername]; isConflict {
|
|
||||||
yamlParsingErrors.Errors = append(yamlParsingErrors.Errors, fmt.Errorf("%q: GitHub name %s conflicts with field defined in %q", processed.FilePath, processed.GithubUsername, prev.FilePath))
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
frontmatterByUsername[processed.GithubUsername] = processed
|
|
||||||
}
|
}
|
||||||
if len(yamlParsingErrors.Errors) != 0 {
|
if len(yamlParsingErrors) != 0 {
|
||||||
return nil, yamlParsingErrors
|
return nil, validationPhaseError{
|
||||||
|
Phase: "YAML parsing",
|
||||||
|
Errors: yamlParsingErrors,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
employeeGithubGroups := map[string][]string{}
|
employeeGithubGroups := map[string][]string{}
|
||||||
yamlValidationErrors := validationPhaseError{
|
yamlValidationErrors := []error{}
|
||||||
Phase: "Raw YAML Validation",
|
|
||||||
}
|
|
||||||
for _, yml := range frontmatterByUsername {
|
for _, yml := range frontmatterByUsername {
|
||||||
errors := validateContributorYaml(yml)
|
errors := validateContributorYaml(yml)
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
yamlValidationErrors.Errors = append(
|
yamlValidationErrors = append(yamlValidationErrors, errors...)
|
||||||
yamlValidationErrors.Errors,
|
|
||||||
errors...,
|
|
||||||
)
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,10 +361,13 @@ func parseContributorFiles(readmeEntries []readme) (
|
|||||||
if _, found := frontmatterByUsername[companyName]; found {
|
if _, found := frontmatterByUsername[companyName]; found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
yamlValidationErrors.Errors = append(yamlValidationErrors.Errors, fmt.Errorf("company %q does not exist in %q directory but is referenced by these profiles: [%s]", companyName, rootRegistryPath, strings.Join(group, ", ")))
|
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, ", ")))
|
||||||
}
|
}
|
||||||
if len(yamlValidationErrors.Errors) != 0 {
|
if len(yamlValidationErrors) != 0 {
|
||||||
return nil, yamlValidationErrors
|
return nil, validationPhaseError{
|
||||||
|
Phase: "Raw YAML Validation",
|
||||||
|
Errors: yamlValidationErrors,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return frontmatterByUsername, nil
|
return frontmatterByUsername, nil
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user