Skip to content

Commit

Permalink
fix(internal): detect module for properly generating docs URLs (#4460)
Browse files Browse the repository at this point in the history
Fixes: #4447
  • Loading branch information
codyoss authored Jul 20, 2021
1 parent 4983913 commit 1eaba8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
36 changes: 18 additions & 18 deletions internal/.repo-metadata-full.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"description": "BigQuery Connection API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/connection/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/connection/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -157,7 +157,7 @@
"description": "BigQuery Connection API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/connection/apiv1beta1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/connection/apiv1beta1",
"release_level": "beta",
"library_type": ""
},
Expand All @@ -166,7 +166,7 @@
"description": "BigQuery Data Transfer API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/datatransfer/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/datatransfer/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -175,7 +175,7 @@
"description": "BigQuery Reservation API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/reservation/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/reservation/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -184,7 +184,7 @@
"description": "BigQuery Reservation API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/reservation/apiv1beta1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/reservation/apiv1beta1",
"release_level": "beta",
"library_type": ""
},
Expand All @@ -193,7 +193,7 @@
"description": "BigQuery Storage API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/storage/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/storage/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -202,7 +202,7 @@
"description": "BigQuery Storage API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/storage/apiv1beta1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/storage/apiv1beta1",
"release_level": "beta",
"library_type": ""
},
Expand All @@ -211,7 +211,7 @@
"description": "BigQuery Storage API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/bigquery/storage/apiv1beta2",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/bigquery/latest/storage/apiv1beta2",
"release_level": "beta",
"library_type": ""
},
Expand Down Expand Up @@ -427,7 +427,7 @@
"description": "Cloud Datastore API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/datastore/admin/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/datastore/latest/admin/apiv1",
"release_level": "alpha",
"library_type": ""
},
Expand Down Expand Up @@ -562,7 +562,7 @@
"description": "Cloud Firestore API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/firestore/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -571,7 +571,7 @@
"description": "Cloud Firestore API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/firestore/apiv1/admin",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/firestore/latest/apiv1/admin",
"release_level": "ga",
"library_type": ""
},
Expand Down Expand Up @@ -715,7 +715,7 @@
"description": "Cloud Logging API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/logging/apiv2",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/logging/latest/apiv2",
"release_level": "ga",
"library_type": ""
},
Expand Down Expand Up @@ -958,7 +958,7 @@
"description": "Cloud Pub/Sub API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/pubsub/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/pubsub/latest/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -976,7 +976,7 @@
"description": "Pub/Sub Lite API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/pubsublite/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/pubsublite/latest/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand Down Expand Up @@ -1237,7 +1237,7 @@
"description": "Cloud Spanner Database Admin API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/spanner/admin/database/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/spanner/latest/admin/database/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -1246,7 +1246,7 @@
"description": "Cloud Spanner Instance Admin API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/spanner/admin/instance/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/spanner/latest/admin/instance/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand All @@ -1255,7 +1255,7 @@
"description": "Cloud Spanner API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/spanner/apiv1",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/spanner/latest/apiv1",
"release_level": "ga",
"library_type": ""
},
Expand Down Expand Up @@ -1291,7 +1291,7 @@
"description": "Cloud Storage API",
"language": "Go",
"client_library_type": "generated",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest/storage/internal/apiv2",
"docs_url": "https://cloud.google.com/go/docs/reference/cloud.google.com/go/storage/latest/internal/apiv2",
"release_level": "alpha",
"library_type": ""
},
Expand Down
13 changes: 13 additions & 0 deletions internal/gapicgen/execv/gocmd/gocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,16 @@ func Vet(dir string) error {
c.Dir = dir
return c.Run()
}

// CurrentMod returns the module name of the provided directory.
func CurrentMod(dir string) (string, error) {
log.Println("detecting current module")
c := execv.Command("go", "list", "-m")
c.Dir = dir
var out []byte
var err error
if out, err = c.Output(); err != nil {
return "", err
}
return strings.TrimSpace(string(out)), nil
}
16 changes: 13 additions & 3 deletions internal/gapicgen/generator/gapics.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,16 @@ func (g *GapicGenerator) manifest(confs []*microgenConfig) error {
if err := yaml.NewDecoder(yamlFile).Decode(&yamlConfig); err != nil {
return fmt.Errorf("decode: %v", err)
}
docURL, err := docURL(g.googleCloudDir, conf.importPath)
if err != nil {
return fmt.Errorf("unable to build docs URL: %v", err)
}
entry := manifestEntry{
DistributionName: conf.importPath,
Description: yamlConfig.Title,
Language: "Go",
ClientLibraryType: "generated",
DocsURL: docURL(conf.importPath),
DocsURL: docURL,
ReleaseLevel: conf.releaseLevel,
}
entries[conf.importPath] = entry
Expand Down Expand Up @@ -596,6 +600,12 @@ func (g *GapicGenerator) findModifiedDirs() ([]string, error) {
return dirList, nil
}

func docURL(importPath string) string {
return "https://cloud.google.com/go/docs/reference/" + importPath[:20] + "latest/" + importPath[20:]
func docURL(cloudDir, importPath string) (string, error) {
suffix := strings.TrimPrefix(importPath, "cloud.google.com/go/")
mod, err := gocmd.CurrentMod(filepath.Join(cloudDir, suffix))
if err != nil {
return "", err
}
pkgPath := strings.TrimPrefix(strings.TrimPrefix(importPath, mod), "/")
return "https://cloud.google.com/go/docs/reference/" + mod + "/latest/" + pkgPath, nil
}

0 comments on commit 1eaba8b

Please sign in to comment.