Skip to content

Commit 89e799f

Browse files
committed
Add tarballFromHoster() method to "upstream" receiver
1 parent 9e0385e commit 89e799f

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

make.go

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,13 @@ func downloadFile(filename, url string) error {
102102

103103
// upstream describes the upstream repo we are about to package.
104104
type upstream struct {
105-
tarPath string // path to the generated orig tarball tempfile
106-
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
107-
firstMain string // import path of the first main package within repo, if any
108-
vendorDirs []string // all vendor sub directories, relative to the repo directory
109-
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
110-
hasGodeps bool // whether the Godeps/_workspace directory exists
105+
tarPath string // path to the downloaded or generated orig tarball tempfile
106+
compression string // compression method, either "gz" or "xz"
107+
version string // Debian package upstream version number, e.g. 0.0~git20180204.1d24609
108+
firstMain string // import path of the first main package within repo, if any
109+
vendorDirs []string // all vendor sub directories, relative to the repo directory
110+
repoDeps []string // the repository paths of all dependencies (e.g. github.com/zyedidia/glob)
111+
hasGodeps bool // whether the Godeps/_workspace directory exists
111112
}
112113

113114
func (u *upstream) get(gopath, repo, rev string) error {
@@ -126,6 +127,36 @@ func (u *upstream) get(gopath, repo, rev string) error {
126127
return rr.VCS.Create(dir, rr.Repo)
127128
}
128129

130+
func (u *upstream) tarballFromHoster(repo string) error {
131+
var url string
132+
parts := strings.Split(repo, "/")
133+
if len(parts) < 3 {
134+
return fmt.Errorf("Unsupported hoster")
135+
}
136+
host, owner, project := parts[0], parts[1], parts[2]
137+
138+
switch host {
139+
case "github.com":
140+
url = fmt.Sprintf("https://%s/%s/%s/archive/v%s.tar.%s",
141+
host, owner, project, u.version, u.compression)
142+
case "gitlab.com":
143+
url = fmt.Sprintf("https://%s/%s/%s/-/archive/v%s/%s-%s.tar.%s",
144+
host, owner, project, u.version, project, u.version, u.compression)
145+
default:
146+
return fmt.Errorf("Unsupported hoster")
147+
}
148+
149+
done := make(chan struct{})
150+
go progressSize("Download", u.tarPath, done)
151+
152+
log.Printf("Downloading %s", url)
153+
err := downloadFile(u.tarPath, url)
154+
155+
close(done)
156+
157+
return err
158+
}
159+
129160
func (u *upstream) tar(gopath, repo string) error {
130161
f, err := ioutil.TempFile("", "dh-make-golang")
131162
if err != nil {

0 commit comments

Comments
 (0)