MCPcopy Create free account
hub / github.com/devfile/api / ValidateProjects

Function ValidateProjects

pkg/validation/projects.go:47–83  ·  view source on GitHub ↗

ValidateProjects checks if the project has more than one remote configured then a checkout remote is mandatory and if the checkout remote matches the renote configured

(projects []v1alpha2.Project)

Source from the content-addressed store, hash-verified

45// ValidateProjects checks if the project has more than one remote configured then a checkout
46// remote is mandatory and if the checkout remote matches the renote configured
47func ValidateProjects(projects []v1alpha2.Project) (returnedErr error) {
48
49 for _, project := range projects {
50 var gitSource v1alpha2.GitLikeProjectSource
51 if project.Git != nil {
52 gitSource = project.Git.GitLikeProjectSource
53 } else {
54 continue
55 }
56 switch len(gitSource.Remotes) {
57 case 0:
58
59 newErr := resolveErrorMessageWithImportAttributes(&MissingProjectRemoteError{projectName: project.Name}, project.Attributes)
60 returnedErr = multierror.Append(returnedErr, newErr)
61 case 1:
62 if gitSource.CheckoutFrom != nil && gitSource.CheckoutFrom.Remote != "" {
63 if err := validateRemoteMap(gitSource.Remotes, gitSource.CheckoutFrom.Remote, "project", project.Name); err != nil {
64 newErr := resolveErrorMessageWithImportAttributes(err, project.Attributes)
65 returnedErr = multierror.Append(returnedErr, newErr)
66 }
67 }
68 default: // len(gitSource.Remotes) >= 2
69 if gitSource.CheckoutFrom == nil || gitSource.CheckoutFrom.Remote == "" {
70
71 newErr := resolveErrorMessageWithImportAttributes(&MissingProjectCheckoutFromRemoteError{projectName: project.Name}, project.Attributes)
72 returnedErr = multierror.Append(returnedErr, newErr)
73 continue
74 }
75 if err := validateRemoteMap(gitSource.Remotes, gitSource.CheckoutFrom.Remote, "project", project.Name); err != nil {
76 newErr := resolveErrorMessageWithImportAttributes(err, project.Attributes)
77 returnedErr = multierror.Append(returnedErr, newErr)
78 }
79 }
80 }
81
82 return returnedErr
83}
84
85// validateRemoteMap checks if the checkout remote is present in the project remote map
86func validateRemoteMap(remotes map[string]string, checkoutRemote, objectType, objectName string) error {

Callers 1

TestValidateProjectsFunction · 0.85

Calls 2

validateRemoteMapFunction · 0.85

Tested by 1

TestValidateProjectsFunction · 0.68