diff --git a/tuple/vanity.go b/tuple/vanity.go index eaa1f32..8ac6c2e 100644 --- a/tuple/vanity.go +++ b/tuple/vanity.go @@ -5,6 +5,7 @@ import "regexp" type vanityParser func(string, string) *Tuple var vanity = map[string]vanityParser{ + "bazil.org": bazilOrgParser, "cloud.google.com": cloudGoogleComParser, "code.cloudfoundry.org": codeCloudfoundryOrgParser, "go.etcd.io": goEtcdIoParser, @@ -14,6 +15,7 @@ var vanity = map[string]vanityParser{ "gopkg.in": gopkgInParser, "k8s.io": k8sIoParser, "mvdan.cc": mvdanCcParser, + "rsc.io": rscIoParser, } func tryVanity(pkg, packagePrefix string) (*Tuple, error) { @@ -25,6 +27,20 @@ func tryVanity(pkg, packagePrefix string) (*Tuple, error) { return nil, nil } +// bazil.org/fuse -> github.com/bazil/fuse +var bazilOrgRe = regexp.MustCompile(`\Abazil\.org/([0-9A-Za-z][-0-9A-Za-z]+)\z`) + +func bazilOrgParser(pkg, packagePrefix string) *Tuple { + if !bazilOrgRe.MatchString(pkg) { + return nil + } + sm := bazilOrgRe.FindAllStringSubmatch(pkg, -1) + if len(sm) == 0 { + return nil + } + return newTuple(GH{}, pkg, "bazil", sm[0][1], packagePrefix) +} + // cloud.google.com/go/* -> github.com/googleapis/google-cloud-go var cloudGoogleComRe = regexp.MustCompile(`\Acloud\.google\.com/go(/([0-9A-Za-z][-0-9A-Za-z]+))?\z`) @@ -150,3 +166,17 @@ func mvdanCcParser(pkg, packagePrefix string) *Tuple { } return newTuple(GH{}, pkg, "mvdan", sm[0][1], packagePrefix) } + +// rsc.io/pdf -> github.com/rsc/pdf +var rscIoRe = regexp.MustCompile(`\Arsc\.io/([0-9A-Za-z][-0-9A-Za-z]+)\z`) + +func rscIoParser(pkg, packagePrefix string) *Tuple { + if !rscIoRe.MatchString(pkg) { + return nil + } + sm := rscIoRe.FindAllStringSubmatch(pkg, -1) + if len(sm) == 0 { + return nil + } + return newTuple(GH{}, pkg, "rsc", sm[0][1], packagePrefix) +} diff --git a/tuple/vanity_test.go b/tuple/vanity_test.go index eaf1f4a..a6d2921 100644 --- a/tuple/vanity_test.go +++ b/tuple/vanity_test.go @@ -17,6 +17,14 @@ func testExamples(t *testing.T, name string, fn vanityParser, examples [][]strin } } +func TestParseBazilOrgName(t *testing.T) { + examples := [][]string{ + // name, expected account, expected project + {"bazil.org/fuse", "bazil", "fuse"}, + } + testExamples(t, "bazilOrgParser", bazilOrgParser, examples) +} + func TestCloudGoogleCom(t *testing.T) { examples := [][]string{ // name, expected account, expected project @@ -93,3 +101,11 @@ func TestParseMvdanCcName(t *testing.T) { } testExamples(t, "mvdanCcParser", mvdanCcParser, examples) } + +func TestParseRscIoName(t *testing.T) { + examples := [][]string{ + // name, expected account, expected project + {"rsc.io/pdf", "rsc", "pdf"}, + } + testExamples(t, "rscIoParser", rscIoParser, examples) +}