Skip to content

Commit

Permalink
fix private github zip fetching and add test
Browse files Browse the repository at this point in the history
Signed-off-by: Tony Worm <tony@hofstadter.io>
  • Loading branch information
verdverm committed Aug 8, 2021
1 parent f202e6a commit a3678d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/mod/testdata/vendor__priv_github.txt
@@ -0,0 +1,15 @@
# hof mod vendor - with deps
exec hof mod vendor

-- cue.mods --
module github.com/test/priv-github

cue v0.4.0

require (
github.com/hofstadter-io/hofmod-test-priv-github v0.0.1
)
-- cue.mod/module.cue --
module: "github.com/test/priv-github"

-- dummy_end --
12 changes: 12 additions & 0 deletions lib/yagu/repos/github/fetch.go
Expand Up @@ -4,6 +4,7 @@ import (
"archive/zip"
"bytes"
"fmt"
"os"
"strings"

"github.com/go-git/go-billy/v5"
Expand Down Expand Up @@ -31,6 +32,7 @@ func Fetch(FS billy.Filesystem, owner, repo, tag string) (error) {
if err != nil {
return fmt.Errorf("While fetching branch zipfile for %s/%s@%s\n%w\n", owner, repo, *r.DefaultBranch, err)
}

} else {
tags, err := GetTags(client, owner, repo)
if err != nil {
Expand Down Expand Up @@ -75,6 +77,11 @@ func FetchTagZip(client *github.Client, tag *github.RepositoryTag) (*zip.Reader,
fmt.Println("url:", url)

req := gorequest.New().Get(url)

if token := os.Getenv("GITHUB_TOKEN"); token != "" {
req.SetBasicAuth("github-token", token)
}

resp, data, errs := req.EndBytes()

check := "http2: server sent GOAWAY and closed the connection"
Expand Down Expand Up @@ -104,6 +111,11 @@ func FetchBranchZip(client *github.Client, owner, repo, branch string) (*zip.Rea
url := fmt.Sprintf("https://github.com/%s/%s/archive/refs/heads/%s.zip", owner, repo, branch)

req := gorequest.New().Get(url)

if token := os.Getenv("GITHUB_TOKEN"); token != "" {
req.SetBasicAuth("github-token", token)
}

resp, data, errs := req.EndBytes()

check := "http2: server sent GOAWAY and closed the connection"
Expand Down

0 comments on commit a3678d6

Please sign in to comment.