Skip to content

Commit 5d8d5bd

Browse files
committed
clean up the code
Signed-off-by: Stephanie <yangcao@redhat.com>
1 parent ac993a8 commit 5d8d5bd

File tree

4 files changed

+19
-37
lines changed

4 files changed

+19
-37
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ require (
1515
github.com/openshift/api v0.0.0-20200930075302-db52bc4ef99f
1616
github.com/pkg/errors v0.9.1
1717
github.com/spf13/afero v1.2.2
18-
github.com/stretchr/testify v1.6.1 // indirect
18+
github.com/stretchr/testify v1.6.1
1919
github.com/xeipuuv/gojsonschema v1.2.0
2020
k8s.io/api v0.19.0
2121
k8s.io/apimachinery v0.19.0

go.sum

+1
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
494494
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
495495
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
496496
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
497+
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
497498
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
498499
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
499500
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

pkg/devfile/parser/context/context.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (d *DevfileCtx) Populate() (err error) {
7272
}
7373
klog.V(4).Infof("absolute devfile path: '%s'", d.absPath)
7474
if d.uriMap == nil {
75-
d.uriMap= make(map[string]bool)
75+
d.uriMap = make(map[string]bool)
7676
}
7777
if d.uriMap[d.absPath] {
7878
return fmt.Errorf("URI %v is recursively referenced", d.absPath)
@@ -93,11 +93,7 @@ func (d *DevfileCtx) PopulateFromURL() (err error) {
9393
return err
9494
}
9595
if d.uriMap == nil {
96-
d.uriMap= make(map[string]bool)
97-
}
98-
fmt.Printf("uriMap length is: %v", len(d.uriMap))
99-
for k,_ := range d.uriMap {
100-
fmt.Printf("uriMap now contains: %s", k)
96+
d.uriMap = make(map[string]bool)
10197
}
10298
if d.uriMap[d.url] {
10399
return fmt.Errorf("URI %v is recursively referenced", d.url)
@@ -150,8 +146,6 @@ func (d *DevfileCtx) GetURIMap() map[string]bool {
150146
}
151147

152148
// GetURIMap func returns current devfile uri map
153-
func (d *DevfileCtx) SetURIMap(uriMap map[string]bool){
149+
func (d *DevfileCtx) SetURIMap(uriMap map[string]bool) {
154150
d.uriMap = uriMap
155151
}
156-
157-

pkg/devfile/parser/parse.go

+14-27
Original file line numberDiff line numberDiff line change
@@ -185,51 +185,38 @@ func parseFromURI(uri string, curDevfileCtx devfileCtx.DevfileCtx) (DevfileObj,
185185
}
186186
// NewDevfileCtx
187187
var d DevfileObj
188-
// absolute URL address
189-
if strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://") {
190-
// return ParseFromURL(uri)
191-
d.Ctx = devfileCtx.NewURLDevfileCtx(uri)
192-
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
193-
// Fill the fields of DevfileCtx struct
194-
err = d.Ctx.PopulateFromURL()
195-
if err != nil {
196-
return DevfileObj{}, err
197-
}
198-
return parseDevfile(d, true)
199-
}
188+
absoluteURL := strings.HasPrefix(uri, "http://") || strings.HasPrefix(uri, "https://")
200189

201190
// relative path on disk
202-
if curDevfileCtx.GetAbsPath() != "" {
191+
if !absoluteURL && curDevfileCtx.GetAbsPath() != "" {
203192
d.Ctx = devfileCtx.NewDevfileCtx(path.Join(path.Dir(curDevfileCtx.GetAbsPath()), uri))
204193
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
205194

206195
// Fill the fields of DevfileCtx struct
207196
err = d.Ctx.Populate()
208-
if err!= nil {
197+
if err != nil {
209198
return DevfileObj{}, err
210199
}
211-
// return Parse(path.Join(path.Dir(curDevfileCtx.GetAbsPath()), uri))
212200
return parseDevfile(d, true)
213201
}
214202

215-
if curDevfileCtx.GetURL() != "" {
203+
// absolute URL address
204+
if absoluteURL {
205+
d.Ctx = devfileCtx.NewURLDevfileCtx(uri)
206+
} else if curDevfileCtx.GetURL() != "" {
216207
u, err := url.Parse(curDevfileCtx.GetURL())
217208
if err != nil {
218209
return DevfileObj{}, err
219210
}
220-
221211
u.Path = path.Join(path.Dir(u.Path), uri)
222212
d.Ctx = devfileCtx.NewURLDevfileCtx(u.String())
223-
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
224-
// Fill the fields of DevfileCtx struct
225-
err = d.Ctx.PopulateFromURL()
226-
if err != nil {
227-
return DevfileObj{}, err
228-
}
229-
return parseDevfile(d, true)
230-
// u.String() is the joint absolute URL path
231-
// return ParseFromURL(u.String())
232213
}
214+
d.Ctx.SetURIMap(curDevfileCtx.GetURIMap())
215+
// Fill the fields of DevfileCtx struct
216+
err = d.Ctx.PopulateFromURL()
217+
if err != nil {
218+
return DevfileObj{}, err
219+
}
220+
return parseDevfile(d, true)
233221

234-
return DevfileObj{}, fmt.Errorf("fail to parse from uri: %s", uri)
235222
}

0 commit comments

Comments
 (0)