-
Notifications
You must be signed in to change notification settings - Fork 273
/
git.go
60 lines (53 loc) 路 1.66 KB
/
git.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package framework
import (
"context"
_ "embed"
"fmt"
"path/filepath"
"github.com/aws/eks-anywhere/pkg/api/v1alpha1"
"github.com/aws/eks-anywhere/pkg/filewriter"
"github.com/aws/eks-anywhere/pkg/git"
gitFactory "github.com/aws/eks-anywhere/pkg/git/factory"
"github.com/aws/eks-anywhere/pkg/git/gogit"
)
type GitOptions struct {
Git git.Provider
Writer filewriter.FileWriter
}
func (e *ClusterE2ETest) NewGitOptions(ctx context.Context, cluster *v1alpha1.Cluster, gitOpsConfig *v1alpha1.GitOpsConfig, writer filewriter.FileWriter, repoPath string) (*GitOptions, error) {
if gitOpsConfig == nil {
return nil, nil
}
var localGitRepoPath string
var localGitWriterPath string
if repoPath == "" {
localGitRepoPath = filepath.Join(cluster.Name, "git", gitOpsConfig.Spec.Flux.Github.Repository)
localGitWriterPath = filepath.Join("git", gitOpsConfig.Spec.Flux.Github.Repository)
} else {
localGitRepoPath = repoPath
localGitWriterPath = repoPath
}
gogitOptions := gogit.Options{
RepositoryDirectory: localGitRepoPath,
}
goGit := gogit.New(gogitOptions)
gitProviderFactoryOptions := gitFactory.Options{GithubGitClient: goGit}
gitProviderFactory := gitFactory.New(gitProviderFactoryOptions)
gitProvider, err := gitProviderFactory.BuildProvider(ctx, &gitOpsConfig.Spec)
if err != nil {
return nil, fmt.Errorf("error creating Git provider: %v", err)
}
err = gitProvider.Validate(ctx)
if err != nil {
return nil, err
}
gitwriter, err := writer.WithDir(localGitWriterPath)
if err != nil {
return nil, fmt.Errorf("error creating file writer: %v", err)
}
gitwriter.CleanUpTemp()
return &GitOptions{
Git: gitProvider,
Writer: gitwriter,
}, nil
}