@@ -21,15 +21,18 @@ func ValidateStarterProjects(starterProjects []v1alpha2.StarterProject) error {
21
21
continue
22
22
}
23
23
24
- if len (gitSource .Remotes ) == 0 {
24
+ switch len (gitSource .Remotes ) {
25
+ case 0 :
25
26
errString += fmt .Sprintf ("\n starterProject %s should have at least one remote" , starterProject .Name )
26
- } else if len ( gitSource . Remotes ) > 1 {
27
- errString += fmt . Sprintf ( " \n starterProject %s should have one remote only" , starterProject . Name )
28
- } else if gitSource .CheckoutFrom != nil && gitSource .CheckoutFrom .Remote != "" {
29
- err := validateRemoteMap ( gitSource . Remotes , gitSource . CheckoutFrom . Remote , starterProject . Name )
30
- if err != nil {
31
- errString += fmt . Sprintf ( " \n %s" , err . Error ())
27
+ case 1 :
28
+ if gitSource . CheckoutFrom . Remote != "" {
29
+ err := validateRemoteMap ( gitSource .Remotes , gitSource .CheckoutFrom .Remote , starterProject . Name )
30
+ if err != nil {
31
+ errString += fmt . Sprintf ( " \n %s" , err . Error ())
32
+ }
32
33
}
34
+ default : // len(gitSource.Remotes) >= 2
35
+ errString += fmt .Sprintf ("\n starterProject %s should have one remote only" , starterProject .Name )
33
36
}
34
37
}
35
38
@@ -56,15 +59,21 @@ func ValidateProjects(projects []v1alpha2.Project) error {
56
59
continue
57
60
}
58
61
59
- if len (gitSource .Remotes ) == 0 {
62
+ switch len (gitSource .Remotes ) {
63
+ case 0 :
60
64
errString += fmt .Sprintf ("\n projects %s should have at least one remote" , project .Name )
61
- } else if len (gitSource .Remotes ) > 1 || (gitSource .CheckoutFrom != nil && gitSource .CheckoutFrom .Remote != "" ) {
62
- if len (gitSource .Remotes ) > 1 && (gitSource .CheckoutFrom == nil || (gitSource .CheckoutFrom != nil && gitSource .CheckoutFrom .Remote == "" )) {
65
+ case 1 :
66
+ if gitSource .CheckoutFrom != nil {
67
+ if err := validateRemoteMap (gitSource .Remotes , gitSource .CheckoutFrom .Remote , project .Name ); err != nil {
68
+ errString += fmt .Sprintf ("\n %s" , err .Error ())
69
+ }
70
+ }
71
+ default : // len(gitSource.Remotes) >= 2
72
+ if gitSource .CheckoutFrom == nil || gitSource .CheckoutFrom .Remote == "" {
63
73
errString += fmt .Sprintf ("\n project %s has more than one remote defined, but has no checkoutfrom remote defined" , project .Name )
64
74
continue
65
75
}
66
- err := validateRemoteMap (gitSource .Remotes , gitSource .CheckoutFrom .Remote , project .Name )
67
- if err != nil {
76
+ if err := validateRemoteMap (gitSource .Remotes , gitSource .CheckoutFrom .Remote , project .Name ); err != nil {
68
77
errString += fmt .Sprintf ("\n %s" , err .Error ())
69
78
}
70
79
}
0 commit comments