77 "io/ioutil"
88 "log"
99 "net/http"
10+ "net/url"
1011 "os"
1112 "os/exec"
1213 "os/user"
@@ -133,30 +134,32 @@ func (u *upstream) get(gopath, repo, rev string) error {
133134 return rr .VCS .Create (dir , rr .Repo )
134135}
135136
136- func (u * upstream ) tarballFromHoster (repo string ) error {
137- var url string
138- parts := strings .Split (repo , "/" )
139- if len (parts ) < 3 {
140- return fmt .Errorf ("Unsupported hoster" )
141- }
142- host , owner , project := parts [0 ], parts [1 ], parts [2 ]
137+ func (u * upstream ) tarballFromHoster () error {
138+ var tarURL string
139+ repo := strings .TrimSuffix (u .rr .Repo , ".git" )
140+ repoU , err := url .Parse (repo )
143141
144- switch host {
142+ switch repoU . Host {
145143 case "github.com" :
146- url = fmt .Sprintf ("https://%s/%s/ %s/archive/v%s.tar.%s" ,
147- host , owner , project , u .version , u .compression )
144+ tarURL = fmt .Sprintf ("%s/archive/v%s.tar.%s" ,
145+ repo , u .version , u .compression )
148146 case "gitlab.com" :
149- url = fmt .Sprintf ("https://%s/%s/%s/-/archive/v%s/%s-%s.tar.%s" ,
150- host , owner , project , u .version , project , u .version , u .compression )
147+ parts := strings .Split (repoU .Path , "/" )
148+ if len (parts ) < 3 {
149+ return fmt .Errorf ("Incomplete repo URL: %s" , u .rr .Repo )
150+ }
151+ project := parts [2 ]
152+ tarURL = fmt .Sprintf ("%s/-/archive/v%[3]s/%[2]s-%s.tar.%s" ,
153+ repo , project , u .version , u .compression )
151154 default :
152155 return fmt .Errorf ("Unsupported hoster" )
153156 }
154157
155158 done := make (chan struct {})
156159 go progressSize ("Download" , u .tarPath , done )
157160
158- log .Printf ("Downloading %s" , url )
159- err : = downloadFile (u .tarPath , url )
161+ log .Printf ("Downloading %s" , tarURL )
162+ err = downloadFile (u .tarPath , tarURL )
160163
161164 close (done )
162165
@@ -176,7 +179,7 @@ func (u *upstream) tar(gopath, repo string) error {
176179 log .Printf ("Godeps/_workspace exists, not downloading tarball from hoster." )
177180 } else {
178181 u .compression = "gz"
179- err := u .tarballFromHoster (repo )
182+ err := u .tarballFromHoster ()
180183 if err != nil && err .Error () == "Unsupported hoster" {
181184 log .Printf ("INFO: Hoster does not provide release tarball\n " )
182185 } else {
0 commit comments