2021-02-01 16:22:41 +05:30
|
|
|
package test
|
2021-02-07 20:26:56 -08:00
|
|
|
|
2021-02-01 16:22:41 +05:30
|
|
|
import (
|
2021-03-12 01:16:36 +05:30
|
|
|
"fmt"
|
2021-02-18 01:00:41 +05:30
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
|
2021-02-01 16:22:41 +05:30
|
|
|
"github.com/go-git/go-billy/v5"
|
|
|
|
"github.com/go-git/go-git/v5"
|
2021-03-12 01:16:36 +05:30
|
|
|
"github.com/go-git/go-git/v5/plumbing"
|
2021-02-01 16:22:41 +05:30
|
|
|
"github.com/go-git/go-git/v5/storage/memory"
|
|
|
|
)
|
|
|
|
|
2021-03-12 01:16:36 +05:30
|
|
|
func clone(path string, fs billy.Filesystem, branch string) (*git.Repository, error) {
|
2021-02-01 16:22:41 +05:30
|
|
|
return git.Clone(memory.NewStorage(), fs, &git.CloneOptions{
|
2021-03-12 01:16:36 +05:30
|
|
|
URL: path,
|
|
|
|
ReferenceName: plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", branch)),
|
|
|
|
Progress: os.Stdout,
|
|
|
|
SingleBranch: true,
|
2022-02-23 12:30:26 +00:00
|
|
|
Depth: 1,
|
2021-02-01 16:22:41 +05:30
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func listYAMLs(fs billy.Filesystem, path string) ([]string, error) {
|
|
|
|
path = filepath.Clean(path)
|
2021-12-20 11:39:53 +05:30
|
|
|
|
|
|
|
if _, err := fs.Stat(path); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-02-01 16:22:41 +05:30
|
|
|
fis, err := fs.ReadDir(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
yamls := make([]string, 0)
|
2021-12-20 11:39:53 +05:30
|
|
|
|
2021-02-01 16:22:41 +05:30
|
|
|
for _, fi := range fis {
|
|
|
|
name := filepath.Join(path, fi.Name())
|
|
|
|
if fi.IsDir() {
|
2021-02-18 01:00:41 +05:30
|
|
|
moreYAMLs, err := listYAMLs(fs, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
yamls = append(yamls, moreYAMLs...)
|
2021-02-01 16:22:41 +05:30
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
ext := filepath.Ext(name)
|
|
|
|
if ext != ".yml" && ext != ".yaml" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
yamls = append(yamls, name)
|
|
|
|
}
|
|
|
|
return yamls, nil
|
|
|
|
}
|