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,35 @@ 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" )
137
+ func (u * upstream ) tarballFromHoster () error {
138
+ var tarURL string
139
+ repo := strings .TrimSuffix (u .rr .Repo , ".git" )
140
+ repoU , err := url .Parse (repo )
141
+ if err != nil {
142
+ return err
141
143
}
142
- host , owner , project := parts [0 ], parts [1 ], parts [2 ]
143
144
144
- switch host {
145
+ switch repoU . Host {
145
146
case "github.com" :
146
- url = fmt .Sprintf ("https://%s/%s/ %s/archive/v%s.tar.%s" ,
147
- host , owner , project , u .version , u .compression )
147
+ tarURL = fmt .Sprintf ("%s/archive/v%s.tar.%s" ,
148
+ repo , u .version , u .compression )
148
149
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 )
150
+ parts := strings .Split (repoU .Path , "/" )
151
+ if len (parts ) < 3 {
152
+ return fmt .Errorf ("Incomplete repo URL: %s" , u .rr .Repo )
153
+ }
154
+ project := parts [2 ]
155
+ tarURL = fmt .Sprintf ("%s/-/archive/v%[3]s/%[2]s-%s.tar.%s" ,
156
+ repo , project , u .version , u .compression )
151
157
default :
152
158
return fmt .Errorf ("Unsupported hoster" )
153
159
}
154
160
155
161
done := make (chan struct {})
156
162
go progressSize ("Download" , u .tarPath , done )
157
163
158
- log .Printf ("Downloading %s" , url )
159
- err : = downloadFile (u .tarPath , url )
164
+ log .Printf ("Downloading %s" , tarURL )
165
+ err = downloadFile (u .tarPath , tarURL )
160
166
161
167
close (done )
162
168
@@ -176,7 +182,7 @@ func (u *upstream) tar(gopath, repo string) error {
176
182
log .Printf ("Godeps/_workspace exists, not downloading tarball from hoster." )
177
183
} else {
178
184
u .compression = "gz"
179
- err := u .tarballFromHoster (repo )
185
+ err := u .tarballFromHoster ()
180
186
if err != nil && err .Error () == "Unsupported hoster" {
181
187
log .Printf ("INFO: Hoster does not provide release tarball\n " )
182
188
} else {
@@ -537,48 +543,40 @@ func normalizeDebianProgramName(str string) string {
537
543
}
538
544
539
545
func shortHostName (gopkg string , allowUnknownHoster bool ) (host string , err error ) {
546
+ knownHosts := map [string ]string {
547
+ // keep the list in alphabetical order
548
+ "bazil.org" : "bazil" ,
549
+ "bitbucket.org" : "bitbucket" ,
550
+ "blitiri.com.ar" : "blitiri" ,
551
+ "cloud.google.com" : "googlecloud" ,
552
+ "code.google.com" : "googlecode" ,
553
+ "git.sr.ht" : "sourcehut" ,
554
+ "github.com" : "github" ,
555
+ "gitlab.com" : "gitlab" ,
556
+ "go.uber.org" : "uber" ,
557
+ "go4.org" : "go4" ,
558
+ "gocloud.dev" : "gocloud" ,
559
+ "golang.org" : "golang" ,
560
+ "google.golang.org" : "google" ,
561
+ "gopkg.in" : "gopkg" ,
562
+ "howett.net" : "howett" ,
563
+ "k8s.io" : "k8s" ,
564
+ "pault.ag" : "pault" ,
565
+ "salsa.debian.org" : "debian" ,
566
+ "sigs.k8s.io" : "k8s-sigs" ,
567
+ }
540
568
parts := strings .Split (gopkg , "/" )
541
569
fqdn := parts [0 ]
542
-
543
- switch fqdn {
544
- case "github.com" :
545
- host = "github"
546
- case "code.google.com" :
547
- host = "googlecode"
548
- case "cloud.google.com" :
549
- host = "googlecloud"
550
- case "gopkg.in" :
551
- host = "gopkg"
552
- case "golang.org" :
553
- host = "golang"
554
- case "google.golang.org" :
555
- host = "google"
556
- case "gitlab.com" :
557
- host = "gitlab"
558
- case "bitbucket.org" :
559
- host = "bitbucket"
560
- case "bazil.org" :
561
- host = "bazil"
562
- case "blitiri.com.ar" :
563
- host = "blitiri"
564
- case "pault.ag" :
565
- host = "pault"
566
- case "howett.net" :
567
- host = "howett"
568
- case "go4.org" :
569
- host = "go4"
570
- case "salsa.debian.org" :
571
- host = "debian"
572
- default :
573
- if allowUnknownHoster {
574
- suffix , _ := publicsuffix .PublicSuffix (host )
575
- host = fqdn [:len (fqdn )- len (suffix )- len ("." )]
576
- log .Printf ("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n " , host , fqdn , os .Args [0 ])
577
- } else {
578
- err = fmt .Errorf ("unknown hoster %q" , fqdn )
579
- }
570
+ if host , ok := knownHosts [fqdn ]; ok {
571
+ return host , nil
572
+ }
573
+ if ! allowUnknownHoster {
574
+ return "" , fmt .Errorf ("unknown hoster %q" , fqdn )
580
575
}
581
- return host , err
576
+ suffix , _ := publicsuffix .PublicSuffix (fqdn )
577
+ host = fqdn [:len (fqdn )- len (suffix )- len ("." )]
578
+ log .Printf ("WARNING: Using %q as canonical hostname for %q. If that is not okay, please file a bug against %s.\n " , host , fqdn , os .Args [0 ])
579
+ return host , nil
582
580
}
583
581
584
582
// debianNameFromGopkg maps a Go package repo path to a Debian package name,
0 commit comments