Init project
Some checks failed
Lint / Run on Ubuntu (push) Has been cancelled
E2E Tests / Run on Ubuntu (push) Has been cancelled
Tests / Run on Ubuntu (push) Has been cancelled

This commit is contained in:
2025-07-15 17:58:36 +02:00
parent 61902f4159
commit 7c2294d9df
77 changed files with 4797 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
package git
import (
"context"
"os"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"sigs.k8s.io/controller-runtime/pkg/log"
)
type GitLib struct {
SSHKey string
SSHKeyPassword string
}
func (g *GitLib) CloneRepo (ctx context.Context, gitURL, revision string) (string, error) {
log := log.FromContext(ctx)
workdir, err := os.MkdirTemp("/tmp", "helmdownloader")
if err != nil {
return "", err
}
log.Info("A temporary directory is created", "path", workdir)
if len(g.SSHKey) > 0 {
keys, err := ssh.NewPublicKeys("git", []byte(g.SSHKey), g.SSHKeyPassword)
if err != nil {
return "", err
}
_, err = git.PlainClone(workdir, false, &git.CloneOptions{URL: gitURL, Auth: keys})
if err != nil {
return "", err
}
} else {
_, err = git.PlainClone(workdir, false, &git.CloneOptions{URL: gitURL})
if err != nil {
return "", err
}
}
return workdir, nil
}

View File

@@ -0,0 +1,15 @@
package git_test
import (
"testing"
"github.com/allanger/yaho/internal/tools/git"
"github.com/stretchr/testify/assert"
)
func TestGitHttpClone(t *testing.T) {
gitlib := &git.GitLib{}
path, err := gitlib.CloneRepo("https://github.com/db-operator/db-operator.git", "main")
assert.NoError(t, err)
assert.Equal(t, "test", path)
}