Skip to content

Commit c34ad7b

Browse files
committed
add bazil.org and rsc.io mirrors
1 parent 6658580 commit c34ad7b

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

tuple/vanity.go

+30
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import "regexp"
55
type vanityParser func(string, string) *Tuple
66

77
var vanity = map[string]vanityParser{
8+
"bazil.org": bazilOrgParser,
89
"cloud.google.com": cloudGoogleComParser,
910
"code.cloudfoundry.org": codeCloudfoundryOrgParser,
1011
"go.etcd.io": goEtcdIoParser,
@@ -14,6 +15,7 @@ var vanity = map[string]vanityParser{
1415
"gopkg.in": gopkgInParser,
1516
"k8s.io": k8sIoParser,
1617
"mvdan.cc": mvdanCcParser,
18+
"rsc.io": rscIoParser,
1719
}
1820

1921
func tryVanity(pkg, packagePrefix string) (*Tuple, error) {
@@ -25,6 +27,20 @@ func tryVanity(pkg, packagePrefix string) (*Tuple, error) {
2527
return nil, nil
2628
}
2729

30+
// bazil.org/fuse -> github.com/bazil/fuse
31+
var bazilOrgRe = regexp.MustCompile(`\Abazil\.org/([0-9A-Za-z][-0-9A-Za-z]+)\z`)
32+
33+
func bazilOrgParser(pkg, packagePrefix string) *Tuple {
34+
if !bazilOrgRe.MatchString(pkg) {
35+
return nil
36+
}
37+
sm := bazilOrgRe.FindAllStringSubmatch(pkg, -1)
38+
if len(sm) == 0 {
39+
return nil
40+
}
41+
return newTuple(GH{}, pkg, "bazil", sm[0][1], packagePrefix)
42+
}
43+
2844
// cloud.google.com/go/* -> github.com/googleapis/google-cloud-go
2945
var cloudGoogleComRe = regexp.MustCompile(`\Acloud\.google\.com/go(/([0-9A-Za-z][-0-9A-Za-z]+))?\z`)
3046

@@ -150,3 +166,17 @@ func mvdanCcParser(pkg, packagePrefix string) *Tuple {
150166
}
151167
return newTuple(GH{}, pkg, "mvdan", sm[0][1], packagePrefix)
152168
}
169+
170+
// rsc.io/pdf -> github.com/rsc/pdf
171+
var rscIoRe = regexp.MustCompile(`\Arsc\.io/([0-9A-Za-z][-0-9A-Za-z]+)\z`)
172+
173+
func rscIoParser(pkg, packagePrefix string) *Tuple {
174+
if !rscIoRe.MatchString(pkg) {
175+
return nil
176+
}
177+
sm := rscIoRe.FindAllStringSubmatch(pkg, -1)
178+
if len(sm) == 0 {
179+
return nil
180+
}
181+
return newTuple(GH{}, pkg, "rsc", sm[0][1], packagePrefix)
182+
}

tuple/vanity_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ func testExamples(t *testing.T, name string, fn vanityParser, examples [][]strin
1717
}
1818
}
1919

20+
func TestParseBazilOrgName(t *testing.T) {
21+
examples := [][]string{
22+
// name, expected account, expected project
23+
{"bazil.org/fuse", "bazil", "fuse"},
24+
}
25+
testExamples(t, "bazilOrgParser", bazilOrgParser, examples)
26+
}
27+
2028
func TestCloudGoogleCom(t *testing.T) {
2129
examples := [][]string{
2230
// name, expected account, expected project
@@ -93,3 +101,11 @@ func TestParseMvdanCcName(t *testing.T) {
93101
}
94102
testExamples(t, "mvdanCcParser", mvdanCcParser, examples)
95103
}
104+
105+
func TestParseRscIoName(t *testing.T) {
106+
examples := [][]string{
107+
// name, expected account, expected project
108+
{"rsc.io/pdf", "rsc", "pdf"},
109+
}
110+
testExamples(t, "rscIoParser", rscIoParser, examples)
111+
}

0 commit comments

Comments
 (0)