@@ -120,7 +120,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
120120 RunE : func (cmd * cobra.Command , args []string ) error {
121121 ctx := cmd .Context ()
122122
123- return RunCreateGitSource (ctx , & GitSourceCreateOptions {
123+ return RunGitSourceCreate (ctx , & GitSourceCreateOptions {
124124 insCloneOpts : insCloneOpts ,
125125 gsCloneOpts : gsCloneOpts ,
126126 gsName : args [1 ],
@@ -144,25 +144,73 @@ func NewGitSourceCreateCommand() *cobra.Command {
144144 return cmd
145145}
146146
147+ func RunGitSourceCreate (ctx context.Context , opts * GitSourceCreateOptions ) error {
148+ gsRepo , gsFs , err := opts .gsCloneOpts .GetRepo (ctx )
149+ if err != nil {
150+ return err
151+ }
152+
153+ fi , err := gsFs .ReadDir ("." )
154+ if err != nil {
155+ return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
156+ }
157+
158+ if len (fi ) == 0 {
159+ if err = createDemoWorkflowTemplate (gsFs , opts .gsName , opts .runtimeName ); err != nil {
160+ return fmt .Errorf ("failed to create demo workflowTemplate: %w" , err )
161+ }
162+
163+ _ , err = gsRepo .Persist (ctx , & git.PushOptions {
164+ CommitMsg : fmt .Sprintf ("Created demo workflow template in %s Directory" , opts .gsCloneOpts .Path ()),
165+ })
166+
167+ if err != nil {
168+ return fmt .Errorf ("failed to push changes. Err: %w" , err )
169+ }
170+ }
171+
172+ appDef := & runtime.AppDef {
173+ Name : opts .gsName ,
174+ Type : application .AppTypeDirectory ,
175+ URL : opts .gsCloneOpts .Repo ,
176+ }
177+ if err := appDef .CreateApp (ctx , nil , opts .insCloneOpts , opts .runtimeName , store .Get ().CFGitSourceType , nil ); err != nil {
178+ return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
179+ }
180+
181+ log .G (ctx ).Infof ("Successfully created the git-source: '%s'" , opts .gsName )
182+
183+ return nil
184+ }
185+
147186func NewGitSourceListCommand () * cobra.Command {
148187 cmd := & cobra.Command {
149188 Use : "list runtime_name" ,
150189 Short : "List all Codefresh git-sources of a given runtime" ,
151190 Example : util .Doc (`<BIN> git-source list my-runtime` ),
152- RunE : func (_ * cobra.Command , args []string ) error {
153- return RunGitSourceList (args [0 ])
191+ PreRun : func (cmd * cobra.Command , args []string ) {
192+ if len (args ) < 1 {
193+ log .G (cmd .Context ()).Fatal ("must enter runtime name" )
194+ }
195+ },
196+ RunE : func (cmd * cobra.Command , args []string ) error {
197+ return RunGitSourceList (cmd .Context (), args [0 ])
154198 },
155199 }
156200 return cmd
157201}
158202
159- func RunGitSourceList (runtimeName string ) error {
160- gitSources , err := cfConfig .NewClient ().GitSource ().List (runtimeName )
161-
203+ func RunGitSourceList (ctx context.Context , runtimeName string ) error {
204+ gitSources , err := cfConfig .NewClient ().V2 ().GitSource ().List (ctx , runtimeName )
162205 if err != nil {
163206 return fmt .Errorf ("failed to get git-sources list. Err: %w" , err )
164207 }
165208
209+ if len (gitSources ) == 0 {
210+ log .G (ctx ).WithField ("runtime" , runtimeName ).Info ("no git-sources were found in runtime" )
211+ return nil
212+ }
213+
166214 tb := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
167215 _ , err = fmt .Fprintln (tb , "NAME\t REPOURL\t PATH\t HEALTH-STATUS\t SYNC-STATUS" )
168216 if err != nil {
@@ -223,7 +271,7 @@ func NewGitSourceDeleteCommand() *cobra.Command {
223271 RunE : func (cmd * cobra.Command , args []string ) error {
224272 ctx := cmd .Context ()
225273
226- return RunDeleteGitSource (ctx , & GitSourceDeleteOptions {
274+ return RunGitSourceDelete (ctx , & GitSourceDeleteOptions {
227275 RuntimeName : args [0 ],
228276 GsName : args [1 ],
229277 Timeout : aputil .MustParseDuration (cmd .Flag ("request-timeout" ).Value .String ()),
@@ -239,6 +287,23 @@ func NewGitSourceDeleteCommand() *cobra.Command {
239287 return cmd
240288}
241289
290+ func RunGitSourceDelete (ctx context.Context , opts * GitSourceDeleteOptions ) error {
291+ err := apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
292+ CloneOpts : opts .InsCloneOpts ,
293+ ProjectName : opts .RuntimeName ,
294+ AppName : opts .GsName ,
295+ Global : false ,
296+ })
297+
298+ if err != nil {
299+ return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
300+ }
301+
302+ log .G (ctx ).Debug ("Successfully deleted the git-source: %s" , opts .GsName )
303+
304+ return nil
305+ }
306+
242307func NewGitSourceEditCommand () * cobra.Command {
243308 var (
244309 insCloneOpts * git.CloneOptions
@@ -272,7 +337,7 @@ func NewGitSourceEditCommand() *cobra.Command {
272337 RunE : func (cmd * cobra.Command , args []string ) error {
273338 ctx := cmd .Context ()
274339
275- return RunEditGitSource (ctx , & GitSourceEditOptions {
340+ return RunGitSourceEdit (ctx , & GitSourceEditOptions {
276341 RuntimeName : args [0 ],
277342 GsName : args [1 ],
278343 InsCloneOpts : insCloneOpts ,
@@ -296,7 +361,7 @@ func NewGitSourceEditCommand() *cobra.Command {
296361 return cmd
297362}
298363
299- func RunEditGitSource (ctx context.Context , opts * GitSourceEditOptions ) error {
364+ func RunGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions ) error {
300365 repo , fs , err := opts .InsCloneOpts .GetRepo (ctx )
301366 if err != nil {
302367 return fmt .Errorf ("failed to clone the installation repo, attemptint to edit git-source %s. Err: %w" , opts .GsName , err )
@@ -328,62 +393,6 @@ func RunEditGitSource(ctx context.Context, opts *GitSourceEditOptions) error {
328393 return nil
329394}
330395
331- func RunCreateGitSource (ctx context.Context , opts * GitSourceCreateOptions ) error {
332- gsRepo , gsFs , err := opts .gsCloneOpts .GetRepo (ctx )
333- if err != nil {
334- return err
335- }
336-
337- fi , err := gsFs .ReadDir ("." )
338- if err != nil {
339- return fmt .Errorf ("failed to read files in git-source repo. Err: %w" , err )
340- }
341-
342- if len (fi ) == 0 {
343- if err = createDemoWorkflowTemplate (gsFs , opts .gsName , opts .runtimeName ); err != nil {
344- return fmt .Errorf ("failed to create demo workflowTemplate: %w" , err )
345- }
346-
347- _ , err = gsRepo .Persist (ctx , & git.PushOptions {
348- CommitMsg : fmt .Sprintf ("Created demo workflow template in %s Directory" , opts .gsCloneOpts .Path ()),
349- })
350-
351- if err != nil {
352- return fmt .Errorf ("failed to push changes. Err: %w" , err )
353- }
354- }
355-
356- appDef := & runtime.AppDef {
357- Name : opts .gsName ,
358- Type : application .AppTypeDirectory ,
359- URL : opts .gsCloneOpts .Repo ,
360- }
361- if err := appDef .CreateApp (ctx , nil , opts .insCloneOpts , opts .runtimeName , store .Get ().CFGitSourceType , nil ); err != nil {
362- return fmt .Errorf ("failed to create git-source application. Err: %w" , err )
363- }
364-
365- log .G (ctx ).Infof ("Successfully created the git-source: '%s'" , opts .gsName )
366-
367- return nil
368- }
369-
370- func RunDeleteGitSource (ctx context.Context , opts * GitSourceDeleteOptions ) error {
371- err := apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
372- CloneOpts : opts .InsCloneOpts ,
373- ProjectName : opts .RuntimeName ,
374- AppName : opts .GsName ,
375- Global : false ,
376- })
377-
378- if err != nil {
379- return fmt .Errorf ("failed to delete the git-source %s. Err: %w" , opts .GsName , err )
380- }
381-
382- log .G (ctx ).Debug ("Successfully deleted the git-source: %s" , opts .GsName )
383-
384- return nil
385- }
386-
387396func createDemoWorkflowTemplate (gsFs fs.FS , gsName , runtimeName string ) error {
388397 wfTemplate := & wfv1alpha1.WorkflowTemplate {
389398 TypeMeta : metav1.TypeMeta {
0 commit comments