7
7
"io/ioutil"
8
8
"log"
9
9
"net/http"
10
+ "net/url"
10
11
"os"
11
12
"os/exec"
12
13
"os/user"
@@ -133,30 +134,32 @@ func (u *upstream) get(gopath, repo, rev string) error {
133
134
return rr .VCS .Create (dir , rr .Repo )
134
135
}
135
136
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 )
143
141
144
- switch host {
142
+ switch repoU . Host {
145
143
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 )
148
146
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 )
151
154
default :
152
155
return fmt .Errorf ("Unsupported hoster" )
153
156
}
154
157
155
158
done := make (chan struct {})
156
159
go progressSize ("Download" , u .tarPath , done )
157
160
158
- log .Printf ("Downloading %s" , url )
159
- err : = downloadFile (u .tarPath , url )
161
+ log .Printf ("Downloading %s" , tarURL )
162
+ err = downloadFile (u .tarPath , tarURL )
160
163
161
164
close (done )
162
165
@@ -176,7 +179,7 @@ func (u *upstream) tar(gopath, repo string) error {
176
179
log .Printf ("Godeps/_workspace exists, not downloading tarball from hoster." )
177
180
} else {
178
181
u .compression = "gz"
179
- err := u .tarballFromHoster (repo )
182
+ err := u .tarballFromHoster ()
180
183
if err != nil && err .Error () == "Unsupported hoster" {
181
184
log .Printf ("INFO: Hoster does not provide release tarball\n " )
182
185
} else {
0 commit comments