Skip to content

Commit

Permalink
fix: update manifest generation to match expected format (#8101)
Browse files Browse the repository at this point in the history
* api_shortname should be populated with DNS prefix of service.
* docs_url should be renamed client_documentation.
* switch Go to go, for consistency with other languages.
* release_level stable/preview, vs., alpha, beta, ga.
  • Loading branch information
bcoe committed Jun 15, 2023
1 parent 4eb8a58 commit 24bd3a0
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions internal/postprocessor/manifest.go
Expand Up @@ -31,13 +31,14 @@ const betaIndicator = "It is not stable"

// ManifestEntry is used for JSON marshaling in manifest.
type ManifestEntry struct {
DistributionName string `json:"distribution_name" yaml:"distribution-name"`
Description string `json:"description" yaml:"description"`
Language string `json:"language" yaml:"language"`
ClientLibraryType string `json:"client_library_type" yaml:"client-library-type"`
DocsURL string `json:"docs_url" yaml:"docs-url"`
ReleaseLevel string `json:"release_level" yaml:"release-level"`
LibraryType libraryType `json:"library_type" yaml:"library-type"`
APIShortname string `json:"api_shortname" yaml:"api-shortname"`
DistributionName string `json:"distribution_name" yaml:"distribution-name"`
Description string `json:"description" yaml:"description"`
Language string `json:"language" yaml:"language"`
ClientLibraryType string `json:"client_library_type" yaml:"client-library-type"`
ClientDocumentation string `json:"client_documentation" yaml:"client-documentation"`
ReleaseLevel string `json:"release_level" yaml:"release-level"`
LibraryType libraryType `json:"library_type" yaml:"library-type"`
}

type libraryType string
Expand Down Expand Up @@ -72,7 +73,8 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
return nil, err
}
yamlConfig := struct {
Title string `yaml:"title"` // We only need the title field.
Title string `yaml:"title"` // We only need the title and name.
NameFull string `yaml:"name"` // We only need the title and name.
}{}
if err := yaml.NewDecoder(yamlFile).Decode(&yamlConfig); err != nil {
return nil, fmt.Errorf("decode: %v", err)
Expand All @@ -86,14 +88,20 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
return nil, fmt.Errorf("unable to calculate release level for %v: %v", inputDir, err)
}

apiShortname, err := apiShortname(yamlConfig.NameFull)
if err != nil {
return nil, fmt.Errorf("unable to determine api_shortname from %v", yamlConfig.NameFull, err)
}

entry := ManifestEntry{
DistributionName: conf.ImportPath,
Description: yamlConfig.Title,
Language: "Go",
ClientLibraryType: "generated",
DocsURL: docURL,
ReleaseLevel: releaseLevel,
LibraryType: gapicAutoLibraryType,
APIShortname: apiShortname,
DistributionName: conf.ImportPath,
Description: yamlConfig.Title,
Language: "go",
ClientLibraryType: "generated",
ClientDocumentation: docURL,
ReleaseLevel: releaseLevel,
LibraryType: gapicAutoLibraryType,
}
entries[conf.ImportPath] = entry
}
Expand All @@ -104,6 +112,16 @@ func (p *postProcessor) Manifest() (map[string]ManifestEntry, error) {
return entries, enc.Encode(entries)
}

// Name is of form secretmanager.googleapis.com api_shortname
// should be prefix secretmanager.
func apiShortname(nameFull string) (string, error) {
nameParts := strings.Split(nameFull, ".")
if len(nameParts) > 0 {
return nameParts[0], nil
}
return "", nil
}

func docURL(cloudDir, importPath, relPath string) (string, error) {
dir := filepath.Join(cloudDir, relPath)
mod, err := gocmd.CurrentMod(dir)
Expand All @@ -118,9 +136,9 @@ func releaseLevel(cloudDir, importPath, relPath string) (string, error) {
i := strings.LastIndex(importPath, "/")
lastElm := importPath[i+1:]
if strings.Contains(lastElm, "alpha") {
return "alpha", nil
return "preview", nil
} else if strings.Contains(lastElm, "beta") {
return "beta", nil
return "preview", nil
}

// Determine by scanning doc.go for our beta disclaimer
Expand All @@ -136,8 +154,8 @@ func releaseLevel(cloudDir, importPath, relPath string) (string, error) {
for scanner.Scan() && lineCnt < 50 {
line := scanner.Text()
if strings.Contains(line, betaIndicator) {
return "beta", nil
return "preview", nil
}
}
return "ga", nil
return "stable", nil
}

0 comments on commit 24bd3a0

Please sign in to comment.