@@ -120,7 +120,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
120
120
RunE : func (cmd * cobra.Command , args []string ) error {
121
121
ctx := cmd .Context ()
122
122
123
- return RunCreateGitSource (ctx , & GitSourceCreateOptions {
123
+ return RunGitSourceCreate (ctx , & GitSourceCreateOptions {
124
124
insCloneOpts : insCloneOpts ,
125
125
gsCloneOpts : gsCloneOpts ,
126
126
gsName : args [1 ],
@@ -144,25 +144,73 @@ func NewGitSourceCreateCommand() *cobra.Command {
144
144
return cmd
145
145
}
146
146
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
+
147
186
func NewGitSourceListCommand () * cobra.Command {
148
187
cmd := & cobra.Command {
149
188
Use : "list runtime_name" ,
150
189
Short : "List all Codefresh git-sources of a given runtime" ,
151
190
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 ])
154
198
},
155
199
}
156
200
return cmd
157
201
}
158
202
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 )
162
205
if err != nil {
163
206
return fmt .Errorf ("failed to get git-sources list. Err: %w" , err )
164
207
}
165
208
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
+
166
214
tb := ansiterm .NewTabWriter (os .Stdout , 0 , 0 , 4 , ' ' , 0 )
167
215
_ , err = fmt .Fprintln (tb , "NAME\t REPOURL\t PATH\t HEALTH-STATUS\t SYNC-STATUS" )
168
216
if err != nil {
@@ -223,7 +271,7 @@ func NewGitSourceDeleteCommand() *cobra.Command {
223
271
RunE : func (cmd * cobra.Command , args []string ) error {
224
272
ctx := cmd .Context ()
225
273
226
- return RunDeleteGitSource (ctx , & GitSourceDeleteOptions {
274
+ return RunGitSourceDelete (ctx , & GitSourceDeleteOptions {
227
275
RuntimeName : args [0 ],
228
276
GsName : args [1 ],
229
277
Timeout : aputil .MustParseDuration (cmd .Flag ("request-timeout" ).Value .String ()),
@@ -239,6 +287,23 @@ func NewGitSourceDeleteCommand() *cobra.Command {
239
287
return cmd
240
288
}
241
289
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
+
242
307
func NewGitSourceEditCommand () * cobra.Command {
243
308
var (
244
309
insCloneOpts * git.CloneOptions
@@ -272,7 +337,7 @@ func NewGitSourceEditCommand() *cobra.Command {
272
337
RunE : func (cmd * cobra.Command , args []string ) error {
273
338
ctx := cmd .Context ()
274
339
275
- return RunEditGitSource (ctx , & GitSourceEditOptions {
340
+ return RunGitSourceEdit (ctx , & GitSourceEditOptions {
276
341
RuntimeName : args [0 ],
277
342
GsName : args [1 ],
278
343
InsCloneOpts : insCloneOpts ,
@@ -296,7 +361,7 @@ func NewGitSourceEditCommand() *cobra.Command {
296
361
return cmd
297
362
}
298
363
299
- func RunEditGitSource (ctx context.Context , opts * GitSourceEditOptions ) error {
364
+ func RunGitSourceEdit (ctx context.Context , opts * GitSourceEditOptions ) error {
300
365
repo , fs , err := opts .InsCloneOpts .GetRepo (ctx )
301
366
if err != nil {
302
367
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 {
328
393
return nil
329
394
}
330
395
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
-
387
396
func createDemoWorkflowTemplate (gsFs fs.FS , gsName , runtimeName string ) error {
388
397
wfTemplate := & wfv1alpha1.WorkflowTemplate {
389
398
TypeMeta : metav1.TypeMeta {
0 commit comments