44 "fmt"
55
66 "github.com/devstream-io/devstream/pkg/util/log"
7- "github.com/devstream-io/devstream/pkg/util/scm"
87 "github.com/devstream-io/devstream/pkg/util/scm/git"
98)
109
@@ -13,23 +12,17 @@ const (
1312)
1413
1514type repoTemplate struct {
16- * scm. SCMInfo `yaml:",inline"`
17- Vars RawOptions `yaml:"vars"`
15+ * git. RepoInfo `yaml:",inline"`
16+ Vars RawOptions `yaml:"vars"`
1817}
1918
2019type app struct {
2120 Name string `yaml:"name" mapstructure:"name"`
2221 Spec * appSpec `yaml:"spec" mapstructure:"spec"`
23- Repo * scm. SCMInfo `yaml:"repo" mapstructure:"repo"`
22+ Repo * git. RepoInfo `yaml:"repo" mapstructure:"repo"`
2423 RepoTemplate * repoTemplate `yaml:"repoTemplate" mapstructure:"repoTemplate"`
2524 CIRawConfigs []pipelineRaw `yaml:"ci" mapstructure:"ci"`
2625 CDRawConfigs []pipelineRaw `yaml:"cd" mapstructure:"cd"`
27-
28- // these two variables is used internal for convince
29- // repoInfo is generated from Repo field with setDefault method
30- repoInfo * git.RepoInfo `yaml:"-" mapstructure:"-"`
31- // repoTemplateInfo is generated from RepoTemplate field with setDefault method
32- repoTemplateInfo * git.RepoInfo `yaml:"-" mapstructure:"-"`
3326}
3427
3528func (a * app ) getTools (vars map [string ]any , templateMap map [string ]string ) (Tools , error ) {
@@ -54,7 +47,7 @@ func (a *app) getTools(vars map[string]any, templateMap map[string]string) (Tool
5447 return tools , nil
5548}
5649
57- // generateAppPipelineTool generate ci/cd tools from app config
50+ // generateCICDTools generate ci/cd tools from app config
5851func (a * app ) generateCICDTools (templateMap map [string ]string , appVars map [string ]any ) (Tools , error ) {
5952 allPipelineRaw := append (a .CIRawConfigs , a .CDRawConfigs ... )
6053 var tools Tools
@@ -78,16 +71,16 @@ func (a *app) generateCICDTools(templateMap map[string]string, appVars map[strin
7871
7972// generateRepoTemplateTool will use repo-scaffolding plugin for app
8073func (a * app ) generateRepoTemplateTool () * Tool {
81- if a .repoTemplateInfo != nil {
74+ if a .RepoTemplate != nil {
8275 templateVars := make (RawOptions )
8376 // templateRepo doesn't need auth info
8477 if a .RepoTemplate .Vars == nil {
8578 templateVars = make (RawOptions )
8679 }
8780 return newTool (
8881 repoScaffoldingPluginName , a .Name , RawOptions {
89- "destinationRepo" : RawOptions (a .repoInfo .Encode ()),
90- "sourceRepo" : RawOptions (a .repoTemplateInfo .Encode ()),
82+ "destinationRepo" : RawOptions (a .Repo .Encode ()),
83+ "sourceRepo" : RawOptions (a .RepoTemplate .Encode ()),
9184 "vars" : templateVars ,
9285 },
9386 )
@@ -100,22 +93,8 @@ func (a *app) setDefault() error {
10093 if a .Repo == nil {
10194 return fmt .Errorf ("configmanager[app] is invalid, repo field must be configured" )
10295 }
103- if a .Repo .Name == "" {
104- a .Repo .Name = a .Name
105- }
106- appRepo , err := a .Repo .BuildRepoInfo ()
107- if err != nil {
108- return fmt .Errorf ("configmanager[app] parse repo failed: %w" , err )
109- }
110- a .repoInfo = appRepo
111- if a .RepoTemplate != nil {
112- // templateRepo doesn't need auth info
113- templateRepo , err := a .RepoTemplate .BuildRepoInfo ()
114- if err != nil {
115- return fmt .Errorf ("configmanager[app] parse repoTemplate failed: %w" , err )
116- }
117- templateRepo .NeedAuth = false
118- a .repoTemplateInfo = templateRepo
96+ if a .Repo .Repo == "" {
97+ a .Repo .Repo = a .Name
11998 }
12099 return nil
121100}
@@ -133,9 +112,8 @@ func (a *app) getRepoTemplateDependants() []string {
133112// newPipelineGlobalOptionFromApp generate pipeline options used for pipeline option configuration
134113func (a * app ) newPipelineGlobalOptionFromApp () * pipelineGlobalOption {
135114 return & pipelineGlobalOption {
136- RepoInfo : a .repoInfo ,
137- AppSpec : a .Spec ,
138- Scm : a .Repo ,
139- AppName : a .Name ,
115+ Repo : a .Repo ,
116+ AppSpec : a .Spec ,
117+ AppName : a .Name ,
140118 }
141119}
0 commit comments