@@ -52,14 +52,13 @@ import (
5252
5353type (
5454 GitSourceCreateOptions struct {
55- InsCloneOpts * git.CloneOptions
56- GsCloneOpts * git.CloneOptions
57- GsName string
58- RuntimeName string
59- FullGsPath string
60- CreateDemoWorkflowTemplate bool
61- Exclude string
62- Include string
55+ InsCloneOpts * git.CloneOptions
56+ GsCloneOpts * git.CloneOptions
57+ GsName string
58+ RuntimeName string
59+ CreateDemoResources bool
60+ Exclude string
61+ Include string
6362 }
6463
6564 GitSourceDeleteOptions struct {
@@ -155,66 +154,34 @@ func NewGitSourceCreateCommand() *cobra.Command {
155154 ctx := cmd .Context ()
156155
157156 return RunGitSourceCreate (ctx , & GitSourceCreateOptions {
158- InsCloneOpts : insCloneOpts ,
159- GsCloneOpts : gsCloneOpts ,
160- GsName : args [1 ],
161- RuntimeName : args [0 ],
162- FullGsPath : gsCloneOpts .Path (),
163- CreateDemoWorkflowTemplate : false ,
157+ InsCloneOpts : insCloneOpts ,
158+ GsCloneOpts : gsCloneOpts ,
159+ GsName : args [1 ],
160+ RuntimeName : args [0 ],
161+ CreateDemoResources : false ,
164162 })
165163 },
166164 }
167165
168- insCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
169- CreateIfNotExist : true ,
170- })
166+ insCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {})
171167 gsCloneOpts = apu .AddCloneFlags (cmd , & apu.CloneFlagsOptions {
172- Prefix : "git-src" ,
173- Optional : true ,
174- CreateIfNotExist : true ,
168+ Prefix : "git-src" ,
169+ Optional : true ,
175170 })
176171
177172 return cmd
178173}
179174
180175func RunGitSourceCreate (ctx context.Context , opts * GitSourceCreateOptions ) error {
181- if opts .CreateDemoWorkflowTemplate {
182-
183- gsRepo , gsFs , err := opts .GsCloneOpts .GetRepo (ctx )
184- if err != nil {
185- return err
186- }
187-
188- fi , err := gsFs .ReadDir ("." )
189- if err != nil {
190- return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
191- }
192-
193- if len (fi ) == 0 {
194- err = createCronExamplePipeline (& gitSourceCronExampleOptions {
195- runtimeName : opts .RuntimeName ,
196- gsCloneOpts : opts .GsCloneOpts ,
197- gsFs : gsFs ,
198- })
199- if err != nil {
200- return fmt .Errorf ("failed to create cron example pipeline. Error: %w" , err )
201- }
202-
203- err = createGithubExamplePipeline (& gitSourceGithubExampleOptions {
204- runtimeName : opts .RuntimeName ,
205- gsCloneOpts : opts .GsCloneOpts ,
206- gsFs : gsFs ,
207- })
208- if err != nil {
209- return fmt .Errorf ("failed to create github example pipeline. Error: %w" , err )
210- }
211-
212- commitMsg := fmt .Sprintf ("Created demo pipelines in %s Directory" , opts .GsCloneOpts .Path ())
176+ // upsert git-source repo
177+ gsRepo , gsFs , err := opts .GsCloneOpts .GetRepo (ctx )
178+ if err != nil {
179+ return fmt .Errorf ("failed to clone git-source repo: %w" , err )
180+ }
213181
214- log .G (ctx ).Info ("Pushing demo pipelines to the new git-source repo" )
215- if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
216- return fmt .Errorf ("failed to push demo pipelines to git-source repo: %w" , err )
217- }
182+ if opts .CreateDemoResources {
183+ if err := createDemoResources (ctx , opts , gsRepo , gsFs ); err != nil {
184+ return fmt .Errorf ("failed to create git source demo resources: %w" , err )
218185 }
219186 }
220187
@@ -227,7 +194,43 @@ func RunGitSourceCreate(ctx context.Context, opts *GitSourceCreateOptions) error
227194 if err := appDef .CreateApp (ctx , nil , opts .InsCloneOpts , opts .RuntimeName , store .Get ().CFGitSourceType , opts .Include , "" ); err != nil {
228195 return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
229196 }
230- log .G (ctx ).Infof ("Successfully created the git-source: '%s'" , opts .GsName )
197+ log .G (ctx ).Infof ("Successfully created git-source: '%s'" , opts .GsName )
198+
199+ return nil
200+ }
201+
202+ func createDemoResources (ctx context.Context , opts * GitSourceCreateOptions , gsRepo git.Repository , gsFs fs.FS ) error {
203+ fi , err := gsFs .ReadDir ("." )
204+ if err != nil {
205+ return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
206+ }
207+
208+ if len (fi ) == 0 {
209+ err = createCronExamplePipeline (& gitSourceCronExampleOptions {
210+ runtimeName : opts .RuntimeName ,
211+ gsCloneOpts : opts .GsCloneOpts ,
212+ gsFs : gsFs ,
213+ })
214+ if err != nil {
215+ return fmt .Errorf ("failed to create cron example pipeline. Error: %w" , err )
216+ }
217+
218+ err = createGithubExamplePipeline (& gitSourceGithubExampleOptions {
219+ runtimeName : opts .RuntimeName ,
220+ gsCloneOpts : opts .GsCloneOpts ,
221+ gsFs : gsFs ,
222+ })
223+ if err != nil {
224+ return fmt .Errorf ("failed to create github example pipeline. Error: %w" , err )
225+ }
226+
227+ commitMsg := fmt .Sprintf ("Created demo pipelines in %s Directory" , opts .GsCloneOpts .Path ())
228+
229+ log .G (ctx ).Info ("Pushing demo pipelines to the new git-source repo" )
230+ if err := apu .PushWithMessage (ctx , gsRepo , commitMsg ); err != nil {
231+ return fmt .Errorf ("failed to push demo pipelines to git-source repo: %w" , err )
232+ }
233+ }
231234
232235 return nil
233236}
0 commit comments