Skip to content

Commit

Permalink
move mod cred helpers to yagu for more general usage
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 fce8f52 commit fe4fbb8
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/mod/cache/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func fetchGitHubTag(FS billy.Filesystem, lang, owner, repo, tag string) error {

zReader, err := github.FetchTagZip(client, T)
if err != nil {
fmt.Printf("Error: %v\n", err)
return fmt.Errorf("While fetching tag zipfile\n%w\n", err)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/yagu/repos/git/netrc.go → lib/yagu/netrc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package git
package yagu

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package git
package yagu

import (
"reflect"
Expand Down
6 changes: 4 additions & 2 deletions lib/yagu/repos/git/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"

"github.com/hofstadter-io/hof/lib/yagu"
)

func NewRemote(srcUrl string) (*GitRepo, error) {
Expand Down Expand Up @@ -106,12 +108,12 @@ func FetchGit(FS billy.Filesystem, remote, owner, repo, tag string, private bool
}

if private {
if netrc, err := NetrcCredentials(remote); err == nil {
if netrc, err := yagu.NetrcCredentials(remote); err == nil {
gco.Auth = &http.BasicAuth{
Username: netrc.Login,
Password: netrc.Password,
}
} else if ssh, err := SSHCredentials(remote); err == nil {
} else if ssh, err := yagu.SSHCredentials(remote); err == nil {
gco.Auth = ssh.Keys
gco.URL = fmt.Sprintf("%s@%s:%s", ssh.User, remote, srcRepo)
} else {
Expand Down
4 changes: 3 additions & 1 deletion lib/yagu/repos/github/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func FetchTagZip(client *github.Client, tag *github.RepositoryTag) (*zip.Reader,

url := *tag.ZipballURL

fmt.Println("url:", url)

req := gorequest.New().Get(url)
resp, data, errs := req.EndBytes()

Expand All @@ -67,7 +69,7 @@ func FetchTagZip(client *github.Client, tag *github.RepositoryTag) (*zip.Reader,
return nil, fmt.Errorf("Internal Error: " + string(resp.StatusCode))
}
if resp.StatusCode >= 400 {
return nil, fmt.Errorf("Bad Request: " + string(resp.StatusCode))
return nil, fmt.Errorf("Bad Request: %v\n%v\n", resp.StatusCode, errs)
}

r := bytes.NewReader(data)
Expand Down
2 changes: 1 addition & 1 deletion lib/yagu/repos/git/ssh.go → lib/yagu/ssh.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package git
package yagu

import (
"os"
Expand Down

0 comments on commit fe4fbb8

Please sign in to comment.