Skip to content

Commit

Permalink
add honnef.co/go/tools mirror, generalize cloud.google.com handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dmgk committed Jan 6, 2020
1 parent df59349 commit ff8bd35
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
4 changes: 2 additions & 2 deletions tuple/mirrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand All @@ -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"},
Expand Down
11 changes: 11 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{
"cloud.google.com": cloudGoogleComParser,
"code.cloudfoundry.org": codeCloudfoundryOrgParser,
"go.etcd.io": goEtcdIoParser,
"go.mozilla.org": goMozillaOrgParser,
Expand All @@ -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`)

Expand Down
11 changes: 10 additions & 1 deletion tuple/vanity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ff8bd35

Please sign in to comment.