11package validation
22
33import (
4- "fmt"
54 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2"
65 "github.com/hashicorp/go-multierror"
76)
87
98// ValidateStarterProjects checks if starter project has only one remote configured
10- // and if the checkout remote matches the renote configured
9+ // and if the checkout remote matches the remote configured
1110func ValidateStarterProjects (starterProjects []v1alpha2.StarterProject ) (returnedErr error ) {
1211
1312 for _ , starterProject := range starterProjects {
@@ -20,8 +19,8 @@ func ValidateStarterProjects(starterProjects []v1alpha2.StarterProject) (returne
2019
2120 switch len (gitSource .Remotes ) {
2221 case 0 :
23- starterProjectErr := fmt . Errorf ( "starterProject %s should have at least one remote" , starterProject . Name )
24- newErr := resolveErrorMessageWithImportAttributes (starterProjectErr , starterProject .Attributes )
22+
23+ newErr := resolveErrorMessageWithImportAttributes (& MissingStarterProjectRemoteError { projectName : starterProject . Name } , starterProject .Attributes )
2524 returnedErr = multierror .Append (returnedErr , newErr )
2625 case 1 :
2726 if gitSource .CheckoutFrom != nil && gitSource .CheckoutFrom .Remote != "" {
@@ -32,8 +31,8 @@ func ValidateStarterProjects(starterProjects []v1alpha2.StarterProject) (returne
3231 }
3332 }
3433 default : // len(gitSource.Remotes) >= 2
35- starterProjectErr := fmt . Errorf ( "starterProject %s should have one remote only" , starterProject . Name )
36- newErr := resolveErrorMessageWithImportAttributes (starterProjectErr , starterProject .Attributes )
34+
35+ newErr := resolveErrorMessageWithImportAttributes (& MultipleStarterProjectRemoteError { projectName : starterProject . Name } , starterProject .Attributes )
3736 returnedErr = multierror .Append (returnedErr , newErr )
3837 }
3938 }
@@ -54,8 +53,8 @@ func ValidateProjects(projects []v1alpha2.Project) (returnedErr error) {
5453 }
5554 switch len (gitSource .Remotes ) {
5655 case 0 :
57- projectErr := fmt . Errorf ( "projects %s should have at least one remote" , project . Name )
58- newErr := resolveErrorMessageWithImportAttributes (projectErr , project .Attributes )
56+
57+ newErr := resolveErrorMessageWithImportAttributes (& MissingProjectRemoteError { projectName : project . Name } , project .Attributes )
5958 returnedErr = multierror .Append (returnedErr , newErr )
6059 case 1 :
6160 if gitSource .CheckoutFrom != nil && gitSource .CheckoutFrom .Remote != "" {
@@ -66,8 +65,8 @@ func ValidateProjects(projects []v1alpha2.Project) (returnedErr error) {
6665 }
6766 default : // len(gitSource.Remotes) >= 2
6867 if gitSource .CheckoutFrom == nil || gitSource .CheckoutFrom .Remote == "" {
69- projectErr := fmt . Errorf ( "project %s has more than one remote defined, but has no checkoutfrom remote defined" , project . Name )
70- newErr := resolveErrorMessageWithImportAttributes (projectErr , project .Attributes )
68+
69+ newErr := resolveErrorMessageWithImportAttributes (& MissingProjectCheckoutFromRemoteError { projectName : project . Name } , project .Attributes )
7170 returnedErr = multierror .Append (returnedErr , newErr )
7271 continue
7372 }
@@ -85,7 +84,8 @@ func ValidateProjects(projects []v1alpha2.Project) (returnedErr error) {
8584func validateRemoteMap (remotes map [string ]string , checkoutRemote , projectName string ) error {
8685
8786 if _ , ok := remotes [checkoutRemote ]; ! ok {
88- return fmt .Errorf ("unable to find the checkout remote %s in the remotes for project %s" , checkoutRemote , projectName )
87+
88+ return & InvalidProjectCheckoutRemoteError {projectName : projectName , checkoutRemote : checkoutRemote }
8989 }
9090
9191 return nil
0 commit comments