Skip to content

Commit ec06eb1

Browse files
lunnyzeripath
andauthored
Fix github download on migration (#14703)
* Fix github download on migration * Use Context for Client Co-authored-by: zeripath <[email protected]>
1 parent ae7e6cd commit ec06eb1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

modules/migrations/github.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
package migrations
77

88
import (
9-
"bytes"
109
"context"
1110
"fmt"
1211
"io"
13-
"io/ioutil"
1412
"net/http"
1513
"net/url"
1614
"strings"
@@ -292,6 +290,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
292290
}
293291

294292
for _, asset := range rel.Assets {
293+
var assetID = *asset.ID // Don't optimize this, for closure we need a local variable
295294
r.Assets = append(r.Assets, &base.ReleaseAsset{
296295
ID: *asset.ID,
297296
Name: *asset.Name,
@@ -302,7 +301,7 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
302301
Updated: asset.UpdatedAt.Time,
303302
DownloadFunc: func() (io.ReadCloser, error) {
304303
g.sleep()
305-
asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, *asset.ID, http.DefaultClient)
304+
asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, assetID, nil)
306305
if err != nil {
307306
return nil, err
308307
}
@@ -311,7 +310,23 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
311310
log.Error("g.client.RateLimits: %s", err)
312311
}
313312
if asset == nil {
314-
return ioutil.NopCloser(bytes.NewBufferString(redir)), nil
313+
if redir != "" {
314+
g.sleep()
315+
req, err := http.NewRequestWithContext(g.ctx, "GET", redir, nil)
316+
if err != nil {
317+
return nil, err
318+
}
319+
resp, err := http.DefaultClient.Do(req)
320+
err1 := g.RefreshRate()
321+
if err1 != nil {
322+
log.Error("g.client.RateLimits: %s", err1)
323+
}
324+
if err != nil {
325+
return nil, err
326+
}
327+
return resp.Body, nil
328+
}
329+
return nil, fmt.Errorf("No release asset found for %d", assetID)
315330
}
316331
return asset, nil
317332
},

0 commit comments

Comments
 (0)