Skip to content

Commit b957898

Browse files
committed
Runs go imports
1 parent abc9b35 commit b957898

File tree

4 files changed

+28
-32
lines changed

4 files changed

+28
-32
lines changed

go.mod

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ go 1.13
55
require (
66
github.com/blang/semver v3.5.0+incompatible
77
github.com/evanphx/json-patch v4.5.0+incompatible
8-
github.com/go-git/go-billy/v5 v5.0.0
98
github.com/go-git/go-git/v5 v5.1.0
109
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
1110
github.com/pkg/errors v0.8.1
1211
github.com/prometheus/client_golang v1.0.0
1312
golang.org/x/tools v0.0.0-20200714190737-9048b464a08d
1413
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
15-
gopkg.in/src-d/go-billy.v4 v4.3.2 // indirect
1614
k8s.io/api v0.18.4
1715
k8s.io/apimachinery v0.18.4
1816
k8s.io/cli-runtime v0.18.4

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ golang.org/x/sys v0.0.0-20190321052220-f7bb7a8bee54/go.mod h1:h1NjWce9XRLGQEsW7w
544544
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
545545
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
546546
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
547-
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
548547
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
549548
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
550549
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7 h1:HmbHVPwrPEKPGLAcHSrMe6+hqSUlvZU0rab6x5EXfGU=
@@ -625,7 +624,6 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
625624
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
626625
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
627626
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
628-
gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98=
629627
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
630628
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
631629
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@ package loaders
33
import (
44
"context"
55
"fmt"
6-
"github.com/go-git/go-git/v5"
76
"io/ioutil"
87
"path"
98
"path/filepath"
9+
"strings"
10+
11+
"github.com/go-git/go-git/v5"
1012
"sigs.k8s.io/controller-runtime/pkg/log"
1113
"sigs.k8s.io/yaml"
12-
"strings"
1314
)
1415

1516
type GitRepository struct {
1617
baseURL string
17-
subDir string
18-
branch string
18+
subDir string
19+
branch string
1920
}
2021

2122
var _ Repository = &GitRepository{}
2223

2324
// NewGitRepository constructs an GitRepository
24-
func NewGitRepository(baseurl string) *GitRepository{
25+
func NewGitRepository(baseurl string) *GitRepository {
2526
repo := parseGitURL(baseurl)
2627
return &repo
2728
}
2829

29-
func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel, error){
30+
func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel, error) {
3031
if !allowedChannelName(name) {
3132
return nil, fmt.Errorf("invalid channel name: %q", name)
3233
}
@@ -39,7 +40,7 @@ func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel
3940
name = r.subDir + "/" + name
4041
}
4142
b, err := r.readURL(name)
42-
if err != nil{
43+
if err != nil {
4344
log.WithValues("path", name).Error(err, "error reading channel")
4445
return nil, err
4546
}
@@ -52,8 +53,7 @@ func (r *GitRepository) LoadChannel(ctx context.Context, name string) (*Channel
5253
return channel, nil
5354
}
5455

55-
56-
func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id string) (map[string]string, error){
56+
func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id string) (map[string]string, error) {
5757
if !allowedManifestId(packageName) {
5858
return nil, fmt.Errorf("invalid package name: %q", id)
5959
}
@@ -67,43 +67,43 @@ func (r *GitRepository) LoadManifest(ctx context.Context, packageName string, id
6767

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

7575
b, err := r.readURL(filePath)
7676

7777
if err != nil {
7878
return nil, fmt.Errorf("error reading package %s: %v", filePath, err)
7979
}
80-
result := map[string]string {
80+
result := map[string]string{
8181
filePath: string(b),
8282
}
8383

84-
return result,nil
84+
return result, nil
8585
}
8686

8787
func (r *GitRepository) readURL(url string) ([]byte, error) {
8888
repoDir := "/tmp/repo"
8989
filePath := filepath.Join(repoDir, url)
9090
fmt.Println(r.baseURL)
9191
_, err := git.PlainClone(repoDir, false, &git.CloneOptions{
92-
URL: r.baseURL,
92+
URL: r.baseURL,
9393
})
9494
if err != nil && err != git.ErrRepositoryAlreadyExists {
9595
return nil, err
9696
}
9797

9898
b, err := ioutil.ReadFile(filePath)
99-
if err != nil{
99+
if err != nil {
100100
return nil, err
101101
}
102102

103103
return b, nil
104104
}
105105

106-
func parseGitURL(url string) GitRepository{
106+
func parseGitURL(url string) GitRepository {
107107
// checks for git:: suffix
108108
var subdir string
109109
if strings.HasPrefix(url, "git::") {

pkg/patterns/addon/pkg/loaders/git_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,35 @@ import (
55
)
66

77
func TestParseGitURL(t *testing.T) {
8-
tests := []struct{
9-
rawURL string
8+
tests := []struct {
9+
rawURL string
1010
baseURL string
11-
subDir string
11+
subDir string
1212
}{
1313
{
14-
rawURL: "https://github.com/testRepository.git",
14+
rawURL: "https://github.com/testRepository.git",
1515
baseURL: "https://github.com/testRepository.git",
16-
subDir: "",
16+
subDir: "",
1717
},
1818
{
19-
rawURL: "git::https://github.com/testRepository.git",
19+
rawURL: "git::https://github.com/testRepository.git",
2020
baseURL: "https://github.com/testRepository.git",
21-
subDir: "",
21+
subDir: "",
2222
},
2323
{
24-
rawURL: "git::https://github.com/testRepository.git//subDir/package",
24+
rawURL: "git::https://github.com/testRepository.git//subDir/package",
2525
baseURL: "https://github.com/testRepository.git",
26-
subDir: "subDir/package",
26+
subDir: "subDir/package",
2727
},
2828
}
2929

3030
for _, tt := range tests {
31-
actualBase, actualSubDir := parseGitURL(tt.rawURL)
32-
if actualBase != tt.baseURL {
31+
gitRepo := parseGitURL(tt.rawURL)
32+
if gitRepo.baseURL != tt.baseURL {
3333
t.Errorf("Expected base url: %v, got %v", tt.baseURL, actualBase)
3434
}
3535

36-
if actualSubDir != tt.subDir {
36+
if gitRepo.subDir != tt.subDir {
3737
t.Errorf("Expected base url: %v, got %v", tt.subDir, actualSubDir)
3838
}
3939
}

0 commit comments

Comments
 (0)