@@ -17,15 +17,18 @@ package commands
1717import (
1818 "context"
1919 "fmt"
20+ "time"
2021
2122 "github.com/codefresh-io/cli-v2/pkg/log"
2223 "github.com/codefresh-io/cli-v2/pkg/runtime"
2324 "github.com/codefresh-io/cli-v2/pkg/store"
2425 "github.com/codefresh-io/cli-v2/pkg/util"
2526
27+ apcmd "github.com/argoproj-labs/argocd-autopilot/cmd/commands"
2628 "github.com/argoproj-labs/argocd-autopilot/pkg/application"
2729 "github.com/argoproj-labs/argocd-autopilot/pkg/fs"
2830 "github.com/argoproj-labs/argocd-autopilot/pkg/git"
31+ aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
2932 wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
3033 wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
3134 "github.com/go-git/go-billy/v5/memfs"
@@ -42,19 +45,28 @@ type (
4245 runtimeName string
4346 fullGsPath string
4447 }
48+
49+ GitSourceDeleteOptions struct {
50+ RuntimeName string
51+ GsName string
52+ CloneOpts * git.CloneOptions
53+ Timeout time.Duration
54+ }
4555)
4656
4757func NewGitSourceCommand () * cobra.Command {
4858 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 ,
5162 Run : func (cmd * cobra.Command , args []string ) {
5263 cmd .HelpFunc ()(cmd , args )
5364 exit (1 )
5465 },
5566 }
5667
5768 cmd .AddCommand (NewGitSourceCreateCommand ())
69+ cmd .AddCommand (NewGitSourceDeleteCommand ())
5870
5971 return cmd
6072}
@@ -69,7 +81,7 @@ func NewGitSourceCreateCommand() *cobra.Command {
6981 Use : "create runtime_name git-source_name" ,
7082 Short : "add a new git-source to an existing runtime" ,
7183 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
7385 ` ),
7486 PreRun : func (cmd * cobra.Command , args []string ) {
7587 ctx := cmd .Context ()
@@ -120,6 +132,49 @@ func NewGitSourceCreateCommand() *cobra.Command {
120132 return cmd
121133}
122134
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+
123178func RunCreateGitSource (ctx context.Context , opts * GitSourceCreateOptions ) error {
124179 gsRepo , gsFs , err := opts .gsCloneOpts .GetRepo (ctx )
125180 if err != nil {
@@ -160,6 +215,23 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
160215 return nil
161216}
162217
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+
163235func createDemoWorkflowTemplate (gsFs fs.FS , gsName , runtimeName string ) error {
164236 wfTemplate := & wfv1alpha1.WorkflowTemplate {
165237 TypeMeta : metav1.TypeMeta {
@@ -186,6 +258,6 @@ func createDemoWorkflowTemplate(gsFs fs.FS, gsName, runtimeName string) error {
186258 },
187259 },
188260 }
189-
261+
190262 return gsFs .WriteYamls ("demo-wf-template.yaml" , wfTemplate )
191263}
0 commit comments