Skip to content

Commit abc9b35

Browse files
committed
Resolves a few nits
1 parent bd390a5 commit abc9b35

File tree

1 file changed

+10
-16
lines changed
  • pkg/patterns/addon/pkg/loaders

1 file changed

+10
-16
lines changed

pkg/patterns/addon/pkg/loaders/git.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import (
55
"fmt"
66
"github.com/go-git/go-git/v5"
77
"io/ioutil"
8-
"os"
8+
"path"
9+
"path/filepath"
910
"sigs.k8s.io/controller-runtime/pkg/log"
1011
"sigs.k8s.io/yaml"
1112
"strings"
@@ -42,11 +43,10 @@ func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel
4243
log.WithValues("path", name).Error(err, "error reading channel")
4344
return nil, err
4445
}
45-
fmt.Println(string(b))
4646

4747
channel := &Channel{}
4848
if err := yaml.Unmarshal(b, channel); err != nil {
49-
return nil, fmt.Errorf("error parsing channel %s: %v", name, err)
49+
return nil, fmt.Errorf("error parsing channel bytes %s: %v", string(b), err)
5050
}
5151

5252
return channel, nil
@@ -67,13 +67,11 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
6767

6868
var filePath string
6969
if r.subDir == "" {
70-
filePath = fmt.Sprintf("packages/%v/%v/manifest.yaml", packageName, id)
70+
filePath = path.Join("packages", packageName, id,"manifest.yaml" )
7171
} else {
72-
filePath = fmt.Sprintf("%v/packages/%v/%v/manifest.yaml", r.subDir, packageName, id)
72+
filePath = path.Join(r.subDir,"packages", packageName, id, "manifest.yaml")
7373
}
7474

75-
fullPath := fmt.Sprintf("%v/%v", r.baseURL, filePath)
76-
fmt.Println(fullPath)
7775
b, err := r.readURL(filePath)
7876

7977
if err != nil {
@@ -88,6 +86,7 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
8886

8987
func (r *GitRepository) readURL(url string) ([]byte, error) {
9088
repoDir := "/tmp/repo"
89+
filePath := filepath.Join(repoDir, url)
9190
fmt.Println(r.baseURL)
9291
_, err := git.PlainClone(repoDir, false, &git.CloneOptions{
9392
URL: r.baseURL,
@@ -96,12 +95,7 @@ func (r *GitRepository) readURL(url string) ([]byte, error) {
9695
return nil, err
9796
}
9897

99-
file, err := os.Open(repoDir + "/" + url)
100-
if err != nil{
101-
return nil, err
102-
}
103-
104-
b, err := ioutil.ReadAll(file)
98+
b, err := ioutil.ReadFile(filePath)
10599
if err != nil{
106100
return nil, err
107101
}
@@ -118,9 +112,9 @@ func parseGitURL(url string) GitRepository{
118112

119113
// checks for subdirectories
120114
if strings.Contains(url, ".git//") {
121-
newURL := strings.Split(url, ".git//")
122-
url = newURL[0] + ".git"
123-
subdir = newURL[1]
115+
urlComponent := strings.SplitN(url, ".git//", 2)
116+
url = urlComponent[0] + ".git"
117+
subdir = urlComponent[1]
124118
}
125119

126120
return GitRepository{

0 commit comments

Comments
 (0)