Skip to content

Commit

Permalink
create a util function to clean white spaces from slice
Browse files Browse the repository at this point in the history
  • Loading branch information
danielm-codefresh committed Feb 20, 2023
1 parent c5acda2 commit 3e94b59
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/git/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/argoproj-labs/argocd-autopilot/pkg/log"
"github.com/argoproj-labs/argocd-autopilot/pkg/store"
"github.com/argoproj-labs/argocd-autopilot/pkg/util"
"github.com/beaconsoftwarellc/gadget/stringutil"

billy "github.com/go-git/go-billy/v5"
gg "github.com/go-git/go-git/v5"
Expand Down Expand Up @@ -506,8 +505,10 @@ var createRepo = func(ctx context.Context, opts *CloneOptions) (defaultBranch st
}

_, orgRepo, _, _, _, _, _ := util.ParseGitUrl(opts.Repo)

// It depends on the provider, but org repo strucure should at least contain org and repo name
if len(stringutil.CleanWhiteSpace(strings.Split(orgRepo, "/"))) < 2 {
slc := util.CleanSliceWhiteSpaces(strings.Split(orgRepo, "/"))
if len(slc) < 2 {
return "", errors.New("repo name can't be empty")
}

Expand Down
11 changes: 11 additions & 0 deletions pkg/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,14 @@ func StealFlags(cmd *cobra.Command, exceptFor []string) (*pflag.FlagSet, error)

return fs, nil
}

func CleanSliceWhiteSpaces(slc []string) []string {
var res []string
for i := range slc {
if slc[i] != "" {
res = append(res, slc[i])
}
}

return res
}
Empty file added pkg/util/util_test.go
Empty file.

0 comments on commit 3e94b59

Please sign in to comment.