refactor: move where validation phase is defined
This commit is contained in:
parent
6e5d960871
commit
94ca584b9e
@ -33,27 +33,6 @@ type contributorProfile struct {
|
|||||||
filePath string
|
filePath string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ error = validationPhaseError{}
|
|
||||||
|
|
||||||
type validationPhaseError struct {
|
|
||||||
phase string
|
|
||||||
errors []error
|
|
||||||
}
|
|
||||||
|
|
||||||
func (vpe validationPhaseError) Error() string {
|
|
||||||
validationStrs := []string{}
|
|
||||||
for _, e := range vpe.errors {
|
|
||||||
validationStrs = append(validationStrs, fmt.Sprintf("- %v", e))
|
|
||||||
}
|
|
||||||
slices.Sort(validationStrs)
|
|
||||||
|
|
||||||
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.phase)
|
|
||||||
msg += strings.Join(validationStrs, "\n")
|
|
||||||
msg += "\n"
|
|
||||||
|
|
||||||
return msg
|
|
||||||
}
|
|
||||||
|
|
||||||
func validateContributorGithubUsername(githubUsername string) error {
|
func validateContributorGithubUsername(githubUsername string) error {
|
||||||
if githubUsername == "" {
|
if githubUsername == "" {
|
||||||
return errors.New("missing GitHub username")
|
return errors.New("missing GitHub username")
|
||||||
@ -219,7 +198,7 @@ func addFilePathToError(filePath string, err error) error {
|
|||||||
return fmt.Errorf("%q: %v", filePath, err)
|
return fmt.Errorf("%q: %v", filePath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateContributorYaml(yml contributorProfile) []error {
|
func validateContributorProfile(yml contributorProfile) []error {
|
||||||
allProblems := []error{}
|
allProblems := []error{}
|
||||||
|
|
||||||
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
|
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
|
||||||
@ -286,7 +265,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
|
|||||||
}
|
}
|
||||||
if len(yamlParsingErrors) != 0 {
|
if len(yamlParsingErrors) != 0 {
|
||||||
return nil, validationPhaseError{
|
return nil, validationPhaseError{
|
||||||
phase: "YAML parsing",
|
phase: validationPhaseReadmeParsing,
|
||||||
errors: yamlParsingErrors,
|
errors: yamlParsingErrors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,7 +273,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
|
|||||||
employeeGithubGroups := map[string][]string{}
|
employeeGithubGroups := map[string][]string{}
|
||||||
yamlValidationErrors := []error{}
|
yamlValidationErrors := []error{}
|
||||||
for _, p := range profilesByUsername {
|
for _, p := range profilesByUsername {
|
||||||
errors := validateContributorYaml(p)
|
errors := validateContributorProfile(p)
|
||||||
if len(errors) > 0 {
|
if len(errors) > 0 {
|
||||||
yamlValidationErrors = append(yamlValidationErrors, errors...)
|
yamlValidationErrors = append(yamlValidationErrors, errors...)
|
||||||
continue
|
continue
|
||||||
@ -315,7 +294,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
|
|||||||
}
|
}
|
||||||
if len(yamlValidationErrors) != 0 {
|
if len(yamlValidationErrors) != 0 {
|
||||||
return nil, validationPhaseError{
|
return nil, validationPhaseError{
|
||||||
phase: "Raw YAML Validation",
|
phase: validationPhaseReadmeValidation,
|
||||||
errors: yamlValidationErrors,
|
errors: yamlValidationErrors,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -352,7 +331,7 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
|
|||||||
|
|
||||||
if len(problems) != 0 {
|
if len(problems) != 0 {
|
||||||
return nil, validationPhaseError{
|
return nil, validationPhaseError{
|
||||||
phase: "FileSystem reading",
|
phase: validationPhaseFilesystemRead,
|
||||||
errors: problems,
|
errors: problems,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -395,7 +374,7 @@ func validateContributorRelativeUrls(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return validationPhaseError{
|
return validationPhaseError{
|
||||||
phase: "Relative URL validation",
|
phase: validationPhaseAssetCrossReference,
|
||||||
errors: problems,
|
errors: problems,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -105,18 +105,18 @@ func (p validationPhase) String() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ error = ValidationPhaseError{}
|
var _ error = validationPhaseError{}
|
||||||
|
|
||||||
// ValidationPhaseError represents an error that occurred during a specific
|
// validationPhaseError represents an error that occurred during a specific
|
||||||
// phase of README validation. It should be used to collect ALL validation
|
// phase of README validation. It should be used to collect ALL validation
|
||||||
// errors that happened during a specific phase, rather than the first one
|
// errors that happened during a specific phase, rather than the first one
|
||||||
// encountered.
|
// encountered.
|
||||||
type ValidationPhaseError struct {
|
type validationPhaseError struct {
|
||||||
phase validationPhase
|
phase validationPhase
|
||||||
errors []error
|
errors []error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vpe ValidationPhaseError) Error() string {
|
func (vpe validationPhaseError) Error() string {
|
||||||
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.phase.String())
|
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.phase.String())
|
||||||
for _, e := range vpe.errors {
|
for _, e := range vpe.errors {
|
||||||
msg += fmt.Sprintf("\n- %v", e)
|
msg += fmt.Sprintf("\n- %v", e)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user