1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-31 03:45:17 +00:00
kyverno/pkg/kyverno/test/git.go
Vyankatesh Kudtarkar 274287617a
fix git branch issue in test command (#1697)
Signed-off-by: vyankatesh <vyankatesh@neualto.com>

Co-authored-by: vyankatesh <vyankatesh@neualto.com>
2021-03-11 11:46:36 -08:00

50 lines
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,
})
}
func listYAMLs(fs billy.Filesystem, path string) ([]string, error) {
path = filepath.Clean(path)
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
}