Skip to content

Commit

Permalink
add bazil.org and rsc.io mirrors
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgk committed Feb 14, 2020
1 parent 6658580 commit c34ad7b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tuple/vanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand All @@ -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`)

Expand Down Expand Up @@ -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)
}
16 changes: 16 additions & 0 deletions tuple/vanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

0 comments on commit c34ad7b

Please sign in to comment.