Skip to content

Commit b45756b

Browse files
supertassuanthonyfok
authored andcommitted
make: download tarballs from sr.ht
and add a test for the tarball URL generation.
1 parent f8c615b commit b45756b

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

make.go

+18-9
Original file line numberDiff line numberDiff line change
@@ -139,28 +139,37 @@ func (u *upstream) get(gopath, repo, rev string) error {
139139
return rr.VCS.Create(dir, rr.Repo)
140140
}
141141

142-
func (u *upstream) tarballFromHoster() error {
143-
var tarURL string
142+
func (u *upstream) tarballUrl() (string, error) {
144143
repo := strings.TrimSuffix(u.rr.Repo, ".git")
145144
repoU, err := url.Parse(repo)
146145
if err != nil {
147-
return fmt.Errorf("parse URL: %w", err)
146+
return "", fmt.Errorf("parse URL: %w", err)
148147
}
149148

150149
switch repoU.Host {
151150
case "github.com":
152-
tarURL = fmt.Sprintf("%s/archive/%s.tar.%s",
153-
repo, u.tag, u.compression)
151+
return fmt.Sprintf("%s/archive/%s.tar.%s",
152+
repo, u.tag, u.compression), nil
154153
case "gitlab.com", "salsa.debian.org":
155154
parts := strings.Split(repoU.Path, "/")
156155
if len(parts) < 3 {
157-
return fmt.Errorf("incomplete repo URL: %s", u.rr.Repo)
156+
return "", fmt.Errorf("incomplete repo URL: %s", u.rr.Repo)
158157
}
159158
project := parts[2]
160-
tarURL = fmt.Sprintf("%s/-/archive/%s/%s-%s.tar.%s",
161-
repo, u.tag, project, u.tag, u.compression)
159+
return fmt.Sprintf("%s/-/archive/%s/%s-%s.tar.%s",
160+
repo, u.tag, project, u.tag, u.compression), nil
161+
case "git.sr.ht":
162+
return fmt.Sprintf("%s/archive/%s.tar.%s",
163+
repo, u.tag, u.compression), nil
162164
default:
163-
return errUnsupportedHoster
165+
return "", errUnsupportedHoster
166+
}
167+
}
168+
169+
func (u *upstream) tarballFromHoster() error {
170+
tarURL, err := u.tarballUrl()
171+
if err != nil {
172+
return err
164173
}
165174

166175
done := make(chan struct{})

make_test.go

+29
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package main
22

33
import (
44
"testing"
5+
6+
"golang.org/x/tools/go/vcs"
57
)
68

79
var shortName = []struct {
@@ -67,3 +69,30 @@ func TestDebianNameFromGopkg(t *testing.T) {
6769
}
6870
}
6971
}
72+
73+
var tarballUrl = []struct {
74+
repoRoot string
75+
tag string
76+
compression string
77+
url string
78+
}{
79+
{"https://github.com/Debian/dh-make-golang", "0.6.0", "gz", "https://github.com/Debian/dh-make-golang/archive/0.6.0.tar.gz"},
80+
{"https://github.com/Debian/dh-make-golang.git", "0.6.0", "gz", "https://github.com/Debian/dh-make-golang/archive/0.6.0.tar.gz"},
81+
{"https://gitlab.com/gitlab-org/labkit", "1.3.0", "gz", "https://gitlab.com/gitlab-org/labkit/-/archive/1.3.0/labkit-1.3.0.tar.gz"},
82+
{"https://git.sr.ht/~sircmpwn/getopt", "v1.0.0", "gz", "https://git.sr.ht/~sircmpwn/getopt/archive/v1.0.0.tar.gz"},
83+
}
84+
85+
func TestUpstreamTarmballUrl(t *testing.T) {
86+
for _, tt := range tarballUrl {
87+
u := upstream{
88+
rr: &vcs.RepoRoot{Repo: tt.repoRoot},
89+
compression: tt.compression,
90+
tag: tt.tag,
91+
}
92+
93+
url, _ := u.tarballUrl()
94+
if url != tt.url {
95+
t.Errorf("TestUpstreamTarmballUrl(%q) => %q, want %q", tt.repoRoot, url, tt.url)
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)