55
66 "github.com/devstream-io/devstream/pkg/util/log"
77 "github.com/devstream-io/devstream/pkg/util/scm/git"
8+ "github.com/devstream-io/devstream/pkg/util/validator"
89)
910
1011const (
@@ -17,28 +18,32 @@ type repoTemplate struct {
1718}
1819
1920type app struct {
20- Name string `yaml:"name" mapstructure:"name"`
21- Spec * appSpec `yaml:"spec" mapstructure:"spec"`
22- Repo * git.RepoInfo `yaml:"repo" mapstructure:"repo"`
21+ Name string `yaml:"name" mapstructure:"name" validate:"required" `
22+ Spec * appSpec `yaml:"spec" mapstructure:"spec" validate:"required" `
23+ Repo * git.RepoInfo `yaml:"repo" mapstructure:"repo" validate:"required" `
2324 RepoTemplate * repoTemplate `yaml:"repoTemplate" mapstructure:"repoTemplate"`
2425 CIRawConfigs []pipelineRaw `yaml:"ci" mapstructure:"ci"`
2526 CDRawConfigs []pipelineRaw `yaml:"cd" mapstructure:"cd"`
2627}
2728
2829func (a * app ) getTools (vars map [string ]any , templateMap map [string ]string ) (Tools , error ) {
29- // 1. set app default field repoInfo and repoTemplateInfo
30+ // 1. check app config data is valid
31+ if err := validator .CheckStructError (a ).Combine (); err != nil {
32+ return nil , err
33+ }
34+ // 2. set app default field repoInfo and repoTemplateInfo
3035 if err := a .setDefault (); err != nil {
3136 return nil , err
3237 }
3338
34- // 2 . get ci/cd pipelineTemplates
39+ // 3 . get ci/cd pipelineTemplates
3540 appVars := a .Spec .merge (vars )
3641 tools , err := a .generateCICDTools (templateMap , appVars )
3742 if err != nil {
3843 return nil , fmt .Errorf ("app[%s] get pipeline tools failed: %w" , a .Name , err )
3944 }
4045
41- // 3 . generate app repo and template repo from scmInfo
46+ // 4 . generate app repo and template repo from scmInfo
4247 repoScaffoldingTool := a .generateRepoTemplateTool ()
4348 if repoScaffoldingTool != nil {
4449 tools = append (tools , repoScaffoldingTool )
@@ -58,6 +63,9 @@ func (a *app) generateCICDTools(templateMap map[string]string, appVars map[strin
5863 if err != nil {
5964 return nil , err
6065 }
66+ if err := validator .CheckStructError (t ).Combine (); err != nil {
67+ return nil , err
68+ }
6169 t .updatePipelineVars (pipelineGlobalVars )
6270 pipelineTool , err := t .generatePipelineTool (pipelineGlobalVars )
6371 if err != nil {
@@ -90,9 +98,6 @@ func (a *app) generateRepoTemplateTool() *Tool {
9098
9199// setDefault will set repoName to appName if repo.name field is empty
92100func (a * app ) setDefault () error {
93- if a .Repo == nil {
94- return fmt .Errorf ("configmanager[app] is invalid, repo field must be configured" )
95- }
96101 if a .Repo .Repo == "" {
97102 a .Repo .Repo = a .Name
98103 }
0 commit comments