@@ -14,13 +14,19 @@ import (
14
14
15
15
type GitRepository struct {
16
16
baseURL string
17
+ subDir string
18
+ branch string
17
19
}
18
20
19
21
var _ Repository = & GitRepository {}
20
22
21
23
// NewGitRepository constructs an GitRepository
22
24
func NewGitRepository (baseurl string ) * GitRepository {
23
- return & GitRepository {baseURL : baseurl }
25
+ baseurl , subDir := parseGitUrl (baseurl )
26
+ return & GitRepository {
27
+ baseURL : baseurl ,
28
+ subDir : subDir ,
29
+ }
24
30
}
25
31
26
32
func (r * GitRepository ) LoadChannel (ctx context.Context , name string ) (* Channel , error ){
@@ -32,6 +38,9 @@ func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel
32
38
log .WithValues ("baseURL" , r .baseURL ).Info ("loading channel" )
33
39
log .WithValues ("baseURL" , r .baseURL ).Info ("cloning git repository" )
34
40
41
+ if r .subDir != "" {
42
+ name = r .subDir + "/" + name
43
+ }
35
44
b , err := r .readURL (name )
36
45
if err != nil {
37
46
log .WithValues ("path" , name ).Error (err , "error reading channel" )
@@ -60,7 +69,13 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
60
69
log := log .Log
61
70
log .WithValues ("package" , packageName ).Info ("loading package" )
62
71
63
- filePath := fmt .Sprintf ("packages/%v/%v/manifest.yaml" , packageName , id )
72
+ var filePath string
73
+ if r .subDir == "" {
74
+ filePath = fmt .Sprintf ("packages/%v/%v/manifest.yaml" , packageName , id )
75
+ } else {
76
+ filePath = fmt .Sprintf ("%v/packages/%v/%v/manifest.yaml" , r .subDir , packageName , id )
77
+ }
78
+
64
79
fullPath := fmt .Sprintf ("%v/%v" , r .baseURL , filePath )
65
80
fmt .Println (fullPath )
66
81
b , err := r .readURL (filePath )
@@ -76,16 +91,16 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
76
91
}
77
92
78
93
func (r * GitRepository ) readURL (url string ) ([]byte , error ) {
79
- // Adds support for sub directory
80
- cloneUrl := r .baseURL
81
- if strings .Contains (r .baseURL , ".git//" ) {
82
- newURL := strings .Split (r .baseURL , ".git//" )
83
- cloneUrl = newURL [0 ] + ".git"
84
- url = newURL [1 ] + "/" + url
85
- }
94
+ //// Adds support for sub directory
95
+ // cloneUrl := r.baseURL
96
+ // if strings.Contains(r.baseURL, ".git//") {
97
+ // newURL := strings.Split(r.baseURL, ".git//")
98
+ // cloneUrl = newURL[0] + ".git"
99
+ // url = newURL[1] + "/" + url
100
+ // }
86
101
fs := memfs .New ()
87
102
_ , err := git .Clone (memory .NewStorage (), fs , & git.CloneOptions {
88
- URL : cloneUrl ,
103
+ URL : r . baseURL ,
89
104
})
90
105
if err != nil {
91
106
return nil , err
@@ -103,3 +118,20 @@ func (r *GitRepository) readURL(url string) ([]byte, error) {
103
118
104
119
return b , nil
105
120
}
121
+
122
+ func parseGitUrl (url string ) (string , string ){
123
+ // checks for git:: suffix
124
+ var subdir string
125
+ if strings .HasPrefix (url , "git::" ) {
126
+ url = strings .TrimPrefix (url , "git::" )
127
+ }
128
+
129
+ // checks for subdirectories
130
+ if strings .Contains (url , ".git//" ) {
131
+ newURL := strings .Split (url , ".git//" )
132
+ url = newURL [0 ] + ".git"
133
+ subdir = newURL [1 ]
134
+ }
135
+
136
+ return url , subdir
137
+ }
0 commit comments