Skip to content

Commit 94ca584

Browse files
committed
refactor: move where validation phase is defined
1 parent 6e5d960 commit 94ca584

File tree

2 files changed

+10
-31
lines changed

2 files changed

+10
-31
lines changed

cmd/readmevalidation/contributors.go

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,6 @@ type contributorProfile struct {
3333
filePath string
3434
}
3535

36-
var _ error = validationPhaseError{}
37-
38-
type validationPhaseError struct {
39-
phase string
40-
errors []error
41-
}
42-
43-
func (vpe validationPhaseError) Error() string {
44-
validationStrs := []string{}
45-
for _, e := range vpe.errors {
46-
validationStrs = append(validationStrs, fmt.Sprintf("- %v", e))
47-
}
48-
slices.Sort(validationStrs)
49-
50-
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.phase)
51-
msg += strings.Join(validationStrs, "\n")
52-
msg += "\n"
53-
54-
return msg
55-
}
56-
5736
func validateContributorGithubUsername(githubUsername string) error {
5837
if githubUsername == "" {
5938
return errors.New("missing GitHub username")
@@ -219,7 +198,7 @@ func addFilePathToError(filePath string, err error) error {
219198
return fmt.Errorf("%q: %v", filePath, err)
220199
}
221200

222-
func validateContributorYaml(yml contributorProfile) []error {
201+
func validateContributorProfile(yml contributorProfile) []error {
223202
allProblems := []error{}
224203

225204
if err := validateContributorGithubUsername(yml.frontmatter.GithubUsername); err != nil {
@@ -286,15 +265,15 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
286265
}
287266
if len(yamlParsingErrors) != 0 {
288267
return nil, validationPhaseError{
289-
phase: "YAML parsing",
268+
phase: validationPhaseReadmeParsing,
290269
errors: yamlParsingErrors,
291270
}
292271
}
293272

294273
employeeGithubGroups := map[string][]string{}
295274
yamlValidationErrors := []error{}
296275
for _, p := range profilesByUsername {
297-
errors := validateContributorYaml(p)
276+
errors := validateContributorProfile(p)
298277
if len(errors) > 0 {
299278
yamlValidationErrors = append(yamlValidationErrors, errors...)
300279
continue
@@ -315,7 +294,7 @@ func parseContributorFiles(readmeEntries []readme) (map[string]contributorProfil
315294
}
316295
if len(yamlValidationErrors) != 0 {
317296
return nil, validationPhaseError{
318-
phase: "Raw YAML Validation",
297+
phase: validationPhaseReadmeValidation,
319298
errors: yamlValidationErrors,
320299
}
321300
}
@@ -352,7 +331,7 @@ func aggregateContributorReadmeFiles() ([]readme, error) {
352331

353332
if len(problems) != 0 {
354333
return nil, validationPhaseError{
355-
phase: "FileSystem reading",
334+
phase: validationPhaseFilesystemRead,
356335
errors: problems,
357336
}
358337
}
@@ -395,7 +374,7 @@ func validateContributorRelativeUrls(
395374
return nil
396375
}
397376
return validationPhaseError{
398-
phase: "Relative URL validation",
377+
phase: validationPhaseAssetCrossReference,
399378
errors: problems,
400379
}
401380
}

cmd/readmevalidation/readmes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,18 @@ func (p validationPhase) String() string {
105105
}
106106
}
107107

108-
var _ error = ValidationPhaseError{}
108+
var _ error = validationPhaseError{}
109109

110-
// ValidationPhaseError represents an error that occurred during a specific
110+
// validationPhaseError represents an error that occurred during a specific
111111
// phase of README validation. It should be used to collect ALL validation
112112
// errors that happened during a specific phase, rather than the first one
113113
// encountered.
114-
type ValidationPhaseError struct {
114+
type validationPhaseError struct {
115115
phase validationPhase
116116
errors []error
117117
}
118118

119-
func (vpe ValidationPhaseError) Error() string {
119+
func (vpe validationPhaseError) Error() string {
120120
msg := fmt.Sprintf("Error during %q phase of README validation:", vpe.phase.String())
121121
for _, e := range vpe.errors {
122122
msg += fmt.Sprintf("\n- %v", e)

0 commit comments

Comments
 (0)