Skip to content

Commit

Permalink
chore(internal/postprocessor): add support for root dir OwlBot dest
Browse files Browse the repository at this point in the history
* Fixes post-processor for OwlBot.yaml paths to root dir / for snippets

refs: googleapis#7850
  • Loading branch information
quartzmo committed Apr 28, 2023
1 parent 3a708ea commit 48a7c4c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/.OwlBot.lock.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-go:latest
digest: sha256:630f3a88a869c8bc9c5748bb861ee54a325d09cf02f7211fc54ec111e7944151
digest: sha256:1798d18f0b7ec6d01624cba6ddcc79ab6b7e0ae5b134fdd8c9a3c7339cf97508
4 changes: 2 additions & 2 deletions .github/.OwlBot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,8 @@ deep-copy-regex:
dest: /compute/apiv1
- source: /google/cloud/confidentialcomputing/v1/cloud.google.com/go
dest: /
- source: /google/cloud/confidentialcomputing/v1alpha1/cloud.google.com/go/confidentialcomputing/apiv1alpha1
dest: /confidentialcomputing/apiv1alpha1
- source: /google/cloud/confidentialcomputing/v1alpha1/cloud.google.com/go
dest: /
- source: /google/cloud/contactcenterinsights/v1/cloud.google.com/go/contactcenterinsights/apiv1
dest: /contactcenterinsights/apiv1
- source: /google/container/v1/cloud.google.com/go/container/apiv1
Expand Down
14 changes: 11 additions & 3 deletions internal/postprocessor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (p *postProcessor) loadConfig() error {
InputDirectory string `yaml:"input-directory"`
ServiceConfig string `yaml:"service-config"`
ImportPath string `yaml:"import-path"`
RelPath string `yaml:"rel-path"`
} `yaml:"service-configs"`
ManualClients []*ManifestEntry `yaml:"manual-clients"`
}
Expand Down Expand Up @@ -90,17 +91,24 @@ func (p *postProcessor) loadConfig() error {
c.GoogleapisToImportPath[v.InputDirectory] = &libraryInfo{
ServiceConfig: v.ServiceConfig,
ImportPath: v.ImportPath,
RelPath: v.RelPath,
}
}
for _, v := range owlBotConfig.DeepCopyRegex {
c.ClientRelPaths = append(c.ClientRelPaths, v.Dest)
i := strings.Index(v.Source, "/cloud.google.com/go")
li, ok := c.GoogleapisToImportPath[v.Source[1:i]]
if !ok {
return fmt.Errorf("unable to find value for %q, it may be missing a service config entry", v.Source[1:i])
}
li.ImportPath = v.Source[i+1:]
li.RelPath = v.Dest
if li.ImportPath == "" {
li.ImportPath = v.Source[i+1:]
fmt.Printf("set li.ImportPath from v.Source: %s", v.Source)
}
if li.RelPath == "" {
li.RelPath = strings.TrimPrefix(li.ImportPath, "cloud.google.com/go")
fmt.Printf("set li.RelPath from li.ImportPath: %s", li.ImportPath)
}
c.ClientRelPaths = append(c.ClientRelPaths, li.RelPath)
}
p.config = c
return nil
Expand Down
4 changes: 4 additions & 0 deletions internal/postprocessor/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ service-configs:
service-config: dataplex_v1.yaml
- input-directory: google/cloud/dataproc/v1
service-config: dataproc_v1.yaml
import-path: cloud.google.com/go/dataproc/v2/apiv1
rel-path: /dataproc/apiv1
- input-directory: google/cloud/dataqna/v1alpha
service-config: dataqna_v1alpha.yaml
- input-directory: google/cloud/datastream/v1
Expand Down Expand Up @@ -635,8 +637,10 @@ service-configs:
service-config: compute_v1.yaml
- input-directory: google/cloud/confidentialcomputing/v1
service-config: confidentialcomputing_v1.yaml
import-path: cloud.google.com/go/confidentialcomputing/apiv1
- input-directory: google/cloud/confidentialcomputing/v1alpha1
service-config: confidentialcomputing_v1alpha1.yaml
import-path: cloud.google.com/go/confidentialcomputing/apiv1alpha1
- input-directory: google/devtools/containeranalysis/v1beta1
service-config: containeranalysis_v1beta1.yaml
- input-directory: google/firestore/admin/v1
Expand Down
11 changes: 10 additions & 1 deletion internal/postprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ func (p *postProcessor) UpdateSnippetsMetadata() error {
// OwlBot dest relative paths in ClientRelPaths begin with /, so the
// first path segment is the second element.
moduleName := strings.Split(clientRelPath, "/")[1]
if moduleName == "" {
return errors.New("UpdateSnippetsMetadata: moduleName is empty")
}
log.Println("UpdateSnippetsMetadata: ", clientRelPath)
// Skip if dirs option set and this module is not included.
if len(p.modules) > 0 && !contains(p.modules, moduleName) {
continue
Expand All @@ -328,10 +332,15 @@ func (p *postProcessor) UpdateSnippetsMetadata() error {
return err
}
snpDir := filepath.Join(p.googleCloudDir, "internal", "generated", "snippets", clientRelPath)
metadataFiles, err := filepath.Glob(filepath.Join(snpDir, "snippet_metadata.*.json"))
p := filepath.Join(snpDir, "snippet_metadata.*.json")
metadataFiles, err := filepath.Glob(p)
if err != nil {
return err
}
if len(metadataFiles) == 0 {
log.Println("UpdateSnippetsMetadata: skipping, file not found with glob: ", p)
continue
}
read, err := os.ReadFile(metadataFiles[0])
if err != nil {
return err
Expand Down

0 comments on commit 48a7c4c

Please sign in to comment.