Skip to content

Commit

Permalink
Use GH asset URL instead of browser URL to download releases
Browse files Browse the repository at this point in the history
Fixes #121

Signed-off-by: Marcos Lilljedahl <marcosnils@gmail.com>
  • Loading branch information
marcosnils committed Dec 11, 2021
1 parent fab888d commit d79facb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pkg/providers/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type gitHub struct {
owner string
repo string
tag string
token string
}

func (g *gitHub) Fetch(opts *FetchOpts) (*File, error) {
Expand All @@ -43,7 +44,7 @@ func (g *gitHub) Fetch(opts *FetchOpts) (*File, error) {

candidates := []*assets.Asset{}
for _, a := range release.Assets {
candidates = append(candidates, &assets.Asset{Name: a.GetName(), URL: a.GetBrowserDownloadURL()})
candidates = append(candidates, &assets.Asset{Name: a.GetName(), URL: a.GetURL()})
}
f := assets.NewFilter(&assets.FilterOpts{SkipScoring: opts.All})

Expand All @@ -52,6 +53,11 @@ func (g *gitHub) Fetch(opts *FetchOpts) (*File, error) {
return nil, err
}

gf.ExtraHeaders = map[string]string{"Accept": "application/octet-stream"}
if g.token != "" {
gf.ExtraHeaders["Authorization"] = fmt.Sprintf("token %s", g.token)
}

name, outputFile, err := f.ProcessURL(gf)
if err != nil {
return nil, err
Expand Down Expand Up @@ -112,5 +118,5 @@ func newGitHub(u *url.URL) (Provider, error) {
))
}
client := github.NewClient(tc)
return &gitHub{url: u, client: client, owner: s[1], repo: s[2], tag: tag}, nil
return &gitHub{url: u, client: client, owner: s[1], repo: s[2], tag: tag, token: token}, nil
}

0 comments on commit d79facb

Please sign in to comment.