From ff8bd35aba6a73fe2e27b37136fc4fba5310f65a Mon Sep 17 00:00:00 2001 From: Dmitri Goutnik Date: Mon, 6 Jan 2020 16:30:38 -0500 Subject: [PATCH] add honnef.co/go/tools mirror, generalize cloud.google.com handling --- tuple/mirrors.go | 4 ++-- tuple/vanity.go | 11 +++++++++++ tuple/vanity_test.go | 11 ++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/tuple/mirrors.go b/tuple/mirrors.go index f986d7a..964e09f 100644 --- a/tuple/mirrors.go +++ b/tuple/mirrors.go @@ -5,8 +5,7 @@ var mirrors = map[string]struct { account string project string }{ - "camlistore.org": {source: GH{}, account: "perkeep", project: "perkeep"}, - "cloud.google.com/go": {source: GH{}, account: "googleapis", project: "google-cloud-go"}, + "camlistore.org": {source: GH{}, account: "perkeep", project: "perkeep"}, "contrib.go.opencensus.io/exporter/ocagent": {source: GH{}, account: "census-ecosystem", project: "opencensus-go-exporter-ocagent"}, "docker.io/go-docker": {source: GH{}, account: "docker", project: "go-docker"}, "git.apache.org/thrift.git": {source: GH{}, account: "apache", project: "thrift"}, @@ -23,6 +22,7 @@ var mirrors = map[string]struct { "google.golang.org/grpc": {source: GH{}, account: "grpc", project: "grpc-go"}, "gopkg.in/fsnotify.v1": {source: GH{}, account: "fsnotify", project: "fsnotify"}, // fsnotify is a special case in gopkg.in "gotest.tools": {source: GH{}, account: "gotestyourself", project: "gotest.tools"}, + "honnef.co/go/tools": {source: GH{}, account: "dominikh", project: "go-tools"}, "howett.net/plist": {source: GL{"https://gitlab.howett.net"}, account: "go", project: "plist"}, "layeh.com/radius": {source: GH{}, account: "layeh", project: "radius"}, "sigs.k8s.io/yaml": {source: GH{}, account: "kubernetes-sigs", project: "yaml"}, diff --git a/tuple/vanity.go b/tuple/vanity.go index f0c42f8..eaa1f32 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{ + "cloud.google.com": cloudGoogleComParser, "code.cloudfoundry.org": codeCloudfoundryOrgParser, "go.etcd.io": goEtcdIoParser, "go.mozilla.org": goMozillaOrgParser, @@ -24,6 +25,16 @@ func tryVanity(pkg, packagePrefix string) (*Tuple, error) { return nil, nil } +// 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`) + +func cloudGoogleComParser(pkg, packagePrefix string) *Tuple { + if !cloudGoogleComRe.MatchString(pkg) { + return nil + } + return newTuple(GH{}, pkg, "googleapis", "google-cloud-go", packagePrefix) +} + // code.cloudfoundry.org/gofileutils -> github.com/cloudfoundry/gofileutils var codeCloudfoundryOrgRe = regexp.MustCompile(`\Acode\.cloudfoundry\.org/([0-9A-Za-z][-0-9A-Za-z]+)\z`) diff --git a/tuple/vanity_test.go b/tuple/vanity_test.go index 668cab3..eaf1f4a 100644 --- a/tuple/vanity_test.go +++ b/tuple/vanity_test.go @@ -6,7 +6,7 @@ func testExamples(t *testing.T, name string, fn vanityParser, examples [][]strin for i, x := range examples { tuple := fn(x[0], "vendor") if tuple == nil { - t.Errorf("%s: expected %q to match", name, x[0]) + t.Fatalf("%s: expected %q to match", name, x[0]) } if tuple.Account != x[1] { t.Errorf("%s: expected account to be %q, got %q (example %d)", name, x[1], tuple.Account, i) @@ -17,6 +17,15 @@ func testExamples(t *testing.T, name string, fn vanityParser, examples [][]strin } } +func TestCloudGoogleCom(t *testing.T) { + examples := [][]string{ + // name, expected account, expected project + {"cloud.google.com/go", "googleapis", "google-cloud-go"}, + {"cloud.google.com/go/storage", "googleapis", "google-cloud-go"}, + } + testExamples(t, "cloudGoogleComParser", cloudGoogleComParser, examples) +} + func TestParseCodeCloudfoundryOrg(t *testing.T) { examples := [][]string{ // name, expected account, expected project