@@ -17,15 +17,18 @@ package commands
17
17
import (
18
18
"context"
19
19
"fmt"
20
+ "time"
20
21
21
22
"github.com/codefresh-io/cli-v2/pkg/log"
22
23
"github.com/codefresh-io/cli-v2/pkg/runtime"
23
24
"github.com/codefresh-io/cli-v2/pkg/store"
24
25
"github.com/codefresh-io/cli-v2/pkg/util"
25
26
27
+ apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
26
28
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
27
29
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
28
30
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
31
+ aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
29
32
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
30
33
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
31
34
"github.com/go-git/go-billy/v5/memfs"
@@ -42,19 +45,28 @@ type (
42
45
runtimeName string
43
46
fullGsPath string
44
47
}
48
+
49
+ GitSourceDeleteOptions struct {
50
+ RuntimeName string
51
+ GsName string
52
+ CloneOpts * git.CloneOptions
53
+ Timeout time.Duration
54
+ }
45
55
)
46
56
47
57
func NewGitSourceCommand () * cobra.Command {
48
58
cmd := & cobra.Command {
49
- Use : "git-source" ,
50
- Short : "Manage git-sources of Codefresh runtimes" ,
59
+ Use : "git-source" ,
60
+ Short : "Manage git-sources of Codefresh runtimes" ,
61
+ PersistentPreRunE : cfConfig .RequireAuthentication ,
51
62
Run : func (cmd * cobra.Command , args []string ) {
52
63
cmd .HelpFunc ()(cmd , args )
53
64
exit (1 )
54
65
},
55
66
}
56
67
57
68
cmd .AddCommand (NewGitSourceCreateCommand ())
69
+ cmd .AddCommand (NewGitSourceDeleteCommand ())
58
70
59
71
return cmd
60
72
}
@@ -69,7 +81,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
69
81
Use : "create runtime_name git-source_name" ,
70
82
Short : "add a new git-source to an existing runtime" ,
71
83
Example : util .Doc (`
72
- <BIN> git-source create runtime_name git-source-name https://github.com/owner/repo-name/my-workflow
84
+ <BIN> git-source create runtime_name git-source-name --git-src-repo https://github.com/owner/repo-name/my-workflow
73
85
` ),
74
86
PreRun : func (cmd * cobra.Command , args []string ) {
75
87
ctx := cmd .Context ()
@@ -120,6 +132,49 @@ func NewGitSourceCreateCommand() *cobra.Command {
120
132
return cmd
121
133
}
122
134
135
+ func NewGitSourceDeleteCommand () * cobra.Command {
136
+ var (
137
+ cloneOpts * git.CloneOptions
138
+ )
139
+
140
+ cmd := & cobra.Command {
141
+ Use : "delete runtime_name git-source_name" ,
142
+ Short : "delete a git-source from a runtime" ,
143
+ Example : util .Doc (`
144
+ <BIN> git-source delete runtime_name git-source_name
145
+ ` ),
146
+ PreRun : func (cmd * cobra.Command , args []string ) {
147
+ ctx := cmd .Context ()
148
+
149
+ if len (args ) < 1 {
150
+ log .G (ctx ).Fatal ("must enter runtime name" )
151
+ }
152
+
153
+ if len (args ) < 2 {
154
+ log .G (ctx ).Fatal ("must enter git-source name" )
155
+ }
156
+
157
+ cloneOpts .Parse ()
158
+ },
159
+ RunE : func (cmd * cobra.Command , args []string ) error {
160
+ ctx := cmd .Context ()
161
+
162
+ return RunDeleteGitSource (ctx , & GitSourceDeleteOptions {
163
+ RuntimeName : args [0 ],
164
+ GsName : args [1 ],
165
+ Timeout : aputil .MustParseDuration (cmd .Flag ("request-timeout" ).Value .String ()),
166
+ CloneOpts : cloneOpts ,
167
+ })
168
+ },
169
+ }
170
+
171
+ cloneOpts = git .AddFlags (cmd , & git.AddFlagsOptions {
172
+ FS : memfs .New (),
173
+ })
174
+
175
+ return cmd
176
+ }
177
+
123
178
func RunCreateGitSource (ctx context.Context , opts * GitSourceCreateOptions ) error {
124
179
gsRepo , gsFs , err := opts .gsCloneOpts .GetRepo (ctx )
125
180
if err != nil {
@@ -160,6 +215,23 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
160
215
return nil
161
216
}
162
217
218
+ func RunDeleteGitSource (ctx context.Context , opts * GitSourceDeleteOptions ) error {
219
+ err := apcmd .RunAppDelete (ctx , & apcmd.AppDeleteOptions {
220
+ CloneOpts : opts .CloneOpts ,
221
+ ProjectName : opts .RuntimeName ,
222
+ AppName : opts .GsName ,
223
+ Global : false ,
224
+ })
225
+
226
+ if err != nil {
227
+ return fmt .Errorf ("failed to delete git-source %s. Err: %w" , opts .GsName , err )
228
+ }
229
+
230
+ log .G (ctx ).Debug ("successfully deleted git-source: %s" , opts .GsName )
231
+
232
+ return nil
233
+ }
234
+
163
235
func createDemoWorkflowTemplate (gsFs fs.FS , gsName , runtimeName string ) error {
164
236
wfTemplate := & wfv1alpha1.WorkflowTemplate {
165
237
TypeMeta : metav1.TypeMeta {
@@ -186,6 +258,6 @@ func createDemoWorkflowTemplate(gsFs fs.FS, gsName, runtimeName string) error {
186
258
},
187
259
},
188
260
}
189
-
261
+
190
262
return gsFs .WriteYamls ("demo-wf-template.yaml" , wfTemplate )
191
263
}
0 commit comments