Skip to content

Commit 566256a

Browse files
bug: fix referring to a relative directory from a git hosted tool
1 parent 9d42279 commit 566256a

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

pkg/loader/url.go

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,13 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
105105
return nil, false, err
106106
}
107107

108-
resp, err := http.DefaultClient.Do(req)
108+
data, err := getWithDefaults(req)
109109
if err != nil {
110-
return nil, false, err
111-
} else if resp.StatusCode != http.StatusOK {
112-
return nil, false, fmt.Errorf("error loading %s: %s", url, resp.Status)
110+
return nil, false, fmt.Errorf("error loading %s: %v", url, err)
113111
}
114112

115113
log.Debugf("opened %s", url)
116114

117-
data, err := io.ReadAll(resp.Body)
118-
if err != nil {
119-
return nil, false, fmt.Errorf("error loading %s: %v", url, err)
120-
}
121-
122115
result := &source{
123116
Content: data,
124117
Remote: true,
@@ -138,6 +131,33 @@ func loadURL(ctx context.Context, cache *cache.Client, base *source, name string
138131
return result, true, nil
139132
}
140133

134+
func getWithDefaults(req *http.Request) ([]byte, error) {
135+
originalPath := req.URL.Path
136+
for i, def := range types.DefaultFiles {
137+
base := path.Base(originalPath)
138+
if !strings.Contains(base, ".") {
139+
req.URL.Path = path.Join(originalPath, def)
140+
}
141+
142+
resp, err := http.DefaultClient.Do(req)
143+
if err != nil {
144+
return nil, err
145+
}
146+
defer resp.Body.Close()
147+
148+
if resp.StatusCode == http.StatusNotFound && i != len(types.DefaultFiles)-1 {
149+
continue
150+
}
151+
152+
if resp.StatusCode != http.StatusOK {
153+
return nil, fmt.Errorf("error loading %s: %s", req.URL.String(), resp.Status)
154+
}
155+
156+
return io.ReadAll(resp.Body)
157+
}
158+
panic("unreachable")
159+
}
160+
141161
func ContentFromURL(url string) (string, error) {
142162
cache, err := cache.New()
143163
if err != nil {

0 commit comments

Comments
 (0)