1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 17:37:12 +00:00
kyverno/cmd/cli/kubectl-kyverno/test/git.go
Mritunjay Kumar Sharma b815caef5d
refactor cli code from pkg to cmd (#3591)
* refactor cli code from pkg to cmd

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixes in imports

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixes tests

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* fixed conflicts

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

* moved non-commands to utils

Signed-off-by: Mritunjay Sharma <mritunjaysharma394@gmail.com>

Co-authored-by: Vyankatesh Kudtarkar <vyankateshkd@gmail.com>
2022-04-14 12:20:18 +00:00

57 lines
1.1 KiB
Go

package test
import (
"fmt"
"os"
"path/filepath"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
)
func clone(path string, fs billy.Filesystem, branch string) (*git.Repository, error) {
return git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
URL: path,
ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", branch)),
Progress: os.Stdout,
SingleBranch: true,
Depth: 1,
})
}
func listYAMLs(fs billy.Filesystem, path string) ([]string, error) {
path = filepath.Clean(path)
if _, err := fs.Stat(path); err != nil {
return nil, err
}
fis, err := fs.ReadDir(path)
if err != nil {
return nil, err
}
yamls := make([]string, 0)
for _, fi := range fis {
name := filepath.Join(path, fi.Name())
if fi.IsDir() {
moreYAMLs, err := listYAMLs(fs, name)
if err != nil {
return nil, err
}
yamls = append(yamls, moreYAMLs...)
continue
}
ext := filepath.Ext(name)
if ext != ".yml" && ext != ".yaml" {
continue
}
yamls = append(yamls, name)
}
return yamls, nil
}