Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.0.66
VERSION=v0.0.67
OUT_DIR=dist
YEAR?=$(shell date +"%Y")

Expand Down
128 changes: 113 additions & 15 deletions cmd/commands/git-source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/argoproj-labs/argocd-autopilot/pkg/application"
"github.com/argoproj-labs/argocd-autopilot/pkg/fs"
"github.com/argoproj-labs/argocd-autopilot/pkg/git"
apstore "github.com/argoproj-labs/argocd-autopilot/pkg/store"
aputil "github.com/argoproj-labs/argocd-autopilot/pkg/util"
wf "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow"
wfv1alpha1 "github.com/argoproj/argo-workflows/v3/pkg/apis/workflow/v1alpha1"
Expand All @@ -49,10 +50,17 @@ type (
}

GitSourceDeleteOptions struct {
RuntimeName string
GsName string
CloneOpts *git.CloneOptions
Timeout time.Duration
RuntimeName string
GsName string
InsCloneOpts *git.CloneOptions
Timeout time.Duration
}

GitSourceEditOptions struct {
RuntimeName string
GsName string
InsCloneOpts *git.CloneOptions
GsCloneOpts *git.CloneOptions
}
)

Expand All @@ -70,6 +78,7 @@ func NewGitSourceCommand() *cobra.Command {
cmd.AddCommand(NewGitSourceCreateCommand())
cmd.AddCommand(NewGitSourceListCommand())
cmd.AddCommand(NewGitSourceDeleteCommand())
cmd.AddCommand(NewGitSourceEditCommand())

return cmd
}
Expand Down Expand Up @@ -189,7 +198,7 @@ func RunGitSourceList(runtimeName string) error {

func NewGitSourceDeleteCommand() *cobra.Command {
var (
cloneOpts *git.CloneOptions
insCloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Expand All @@ -209,27 +218,116 @@ func NewGitSourceDeleteCommand() *cobra.Command {
log.G(ctx).Fatal("must enter git-source name")
}

cloneOpts.Parse()
insCloneOpts.Parse()
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

return RunDeleteGitSource(ctx, &GitSourceDeleteOptions{
RuntimeName: args[0],
GsName: args[1],
Timeout: aputil.MustParseDuration(cmd.Flag("request-timeout").Value.String()),
CloneOpts: cloneOpts,
RuntimeName: args[0],
GsName: args[1],
Timeout: aputil.MustParseDuration(cmd.Flag("request-timeout").Value.String()),
InsCloneOpts: insCloneOpts,
})
},
}

cloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
FS: memfs.New(),
})

return cmd
}

func NewGitSourceEditCommand() *cobra.Command {
var (
insCloneOpts *git.CloneOptions
gsCloneOpts *git.CloneOptions
)

cmd := &cobra.Command{
Use: "edit runtime_name git-source_name",
Short: "edit a git-source of a runtime",
Example: util.Doc(`
<BIN> git-source edit runtime_name git-source_name --git-src-repo https://github.com/owner/repo-name/my-workflow
`),
PreRun: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()

if len(args) < 1 {
log.G(ctx).Fatal("must enter a runtime name")
}

if len(args) < 2 {
log.G(ctx).Fatal("must enter a git-source name")
}

if gsCloneOpts.Repo == "" {
log.G(ctx).Fatal("must enter a valid value to --git-src-repo. Example: https://github.com/owner/repo-name/path/to/workflow")
}

insCloneOpts.Parse()
gsCloneOpts.Parse()
},
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()

return RunEditGitSource(ctx, &GitSourceEditOptions{
RuntimeName: args[0],
GsName: args[1],
InsCloneOpts: insCloneOpts,
GsCloneOpts: gsCloneOpts,
})
},
}

insCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
CreateIfNotExist: true,
FS: memfs.New(),
})

gsCloneOpts = git.AddFlags(cmd, &git.AddFlagsOptions{
Prefix: "git-src",
Optional: true,
CreateIfNotExist: true,
FS: memfs.New(),
})

return cmd
}

func RunEditGitSource(ctx context.Context, opts *GitSourceEditOptions) error {
repo, fs, err := opts.InsCloneOpts.GetRepo(ctx)
if err != nil {
return fmt.Errorf("failed to clone the installation repo, attemptint to edit git-source %s. Err: %w", opts.GsName, err)
}

c := &application.Config{}
err = fs.ReadJson(fs.Join(apstore.Default.AppsDir, opts.GsName, opts.RuntimeName, "config.json"), c)
if err != nil {
return fmt.Errorf("failed to read the config.json of git-source: %s. Err: %w", opts.GsName, err)
}

c.SrcPath = opts.GsCloneOpts.Path()
c.SrcRepoURL = opts.GsCloneOpts.URL()
c.SrcTargetRevision = opts.GsCloneOpts.Revision()

err = fs.WriteJson(fs.Join(apstore.Default.AppsDir, opts.GsName, opts.RuntimeName, "config.json"), c)
if err != nil {
return fmt.Errorf("failed to write the updated config.json of git-source: %s. Err: %w", opts.GsName, err)
}

_, err = repo.Persist(ctx, &git.PushOptions{
CommitMsg: "Persisted an updated git-source",
})

if err != nil {
return fmt.Errorf("failed to persist the updated git-source: %s. Err: %w", opts.GsName, err)
}

return nil
}

func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error {
gsRepo, gsFs, err := opts.gsCloneOpts.GetRepo(ctx)
if err != nil {
Expand Down Expand Up @@ -264,24 +362,24 @@ func RunCreateGitSource(ctx context.Context, opts *GitSourceCreateOptions) error
return fmt.Errorf("failed to create git-source application. Err: %w", err)
}

log.G(ctx).Infof("done creating a new git-source: '%s'", opts.gsName)
log.G(ctx).Infof("Successfully created the git-source: '%s'", opts.gsName)

return nil
}

func RunDeleteGitSource(ctx context.Context, opts *GitSourceDeleteOptions) error {
err := apcmd.RunAppDelete(ctx, &apcmd.AppDeleteOptions{
CloneOpts: opts.CloneOpts,
CloneOpts: opts.InsCloneOpts,
ProjectName: opts.RuntimeName,
AppName: opts.GsName,
Global: false,
})

if err != nil {
return fmt.Errorf("failed to delete git-source %s. Err: %w", opts.GsName, err)
return fmt.Errorf("failed to delete the git-source %s. Err: %w", opts.GsName, err)
}

log.G(ctx).Debug("successfully deleted git-source: %s", opts.GsName)
log.G(ctx).Debug("Successfully deleted the git-source: %s", opts.GsName)

return nil
}
Expand Down
1 change: 1 addition & 0 deletions docs/commands/cli-v2_git-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ cli-v2 git-source [flags]
* [cli-v2](cli-v2.md) - cli-v2 is used for installing and managing codefresh installations using gitops
* [cli-v2 git-source create](cli-v2_git-source_create.md) - add a new git-source to an existing runtime
* [cli-v2 git-source delete](cli-v2_git-source_delete.md) - delete a git-source from a runtime
* [cli-v2 git-source edit](cli-v2_git-source_edit.md) - edit a git-source of a runtime
* [cli-v2 git-source list](cli-v2_git-source_list.md) - List all Codefresh git-sources of a given runtime

41 changes: 41 additions & 0 deletions docs/commands/cli-v2_git-source_edit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## cli-v2 git-source edit

edit a git-source of a runtime

```
cli-v2 git-source edit runtime_name git-source_name [flags]
```

### Examples

```

cli-v2 git-source edit runtime_name git-source_name --git-src-repo https://github.com/owner/repo-name/my-workflow

```

### Options

```
--git-src-git-token string Your git provider api token [GIT_SRC_GIT_TOKEN]
--git-src-provider string The git provider, one of: gitea|github
--git-src-repo string Repository URL [GIT_SRC_GIT_REPO]
-t, --git-token string Your git provider api token [GIT_TOKEN]
-h, --help help for edit
--provider string The git provider, one of: gitea|github
--repo string Repository URL [GIT_REPO]
```

### Options inherited from parent commands

```
--auth-context string Run the next command using a specific authentication context
--cfconfig string Custom path for authentication contexts config file (default "/home/user")
--insecure Disable certificate validation for TLS connections (e.g. to g.codefresh.io)
--request-timeout duration Request timeout (default 30s)
```

### SEE ALSO

* [cli-v2 git-source](cli-v2_git-source.md) - Manage git-sources of Codefresh runtimes

4 changes: 2 additions & 2 deletions docs/releases/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ cf version
### Linux
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.66/cf-linux-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.67/cf-linux-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-linux-amd64 /usr/local/bin/cf
Expand All @@ -32,7 +32,7 @@ cf version
### Mac
```bash
# download and extract the binary
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.66/cf-darwin-amd64.tar.gz | tar zx
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.67/cf-darwin-amd64.tar.gz | tar zx

# move the binary to your $PATH
mv ./cf-darwin-amd64 /usr/local/bin/cf
Expand Down
2 changes: 1 addition & 1 deletion manifests/runtime.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
namespace: "{{ namespace }}"
spec:
defVersion: 1.0.0
version: 0.0.66
version: 0.0.67
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
components:
- name: events
Expand Down