Skip to content

Commit 4933410

Browse files
authored
chore(internal/stategen): fix cleanup.go for special-case cloudtasks module (googleapis#13045)
Discover correct `../tasks/..` Go importpath from existing configuration in a generalized solution for all modules.
1 parent 12b6a1a commit 4933410

File tree

9 files changed

+3730
-2
lines changed

9 files changed

+3730
-2
lines changed

internal/stategen/cleanup.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,48 @@ func cleanupOwlBotYaml(repoRoot, moduleName string) error {
238238
return err
239239
}
240240

241+
// Also check for a cleanup name, which may be different from the module name.
242+
// For example, the cloudtasks module has the proto path .../cloud/tasks.
243+
// We can derive this name from the postprocessor config.
244+
ppc, err := loadPostProcessorConfig(filepath.Join(repoRoot, "internal/postprocessor/config.yaml"))
245+
if err != nil {
246+
return fmt.Errorf("loading postprocessor config: %w", err)
247+
}
248+
cleanupName := moduleName // Default to the module name.
249+
importPrefix := "cloud.google.com/go/" + moduleName + "/"
250+
for _, sc := range ppc.ServiceConfigs {
251+
if strings.HasPrefix(sc.ImportPath, importPrefix) {
252+
// The InputDirectory is the path to the API protos, relative to the
253+
// googleapis root. It has a structure like:
254+
// "google/cloud/service/v1" or "google/identity/accesscontextmanager/v1".
255+
// The third component of this path is the service name as it appears
256+
// in the `source:` lines of .OwlBot.yaml.
257+
parts := strings.Split(sc.InputDirectory, "/")
258+
if len(parts) > 2 {
259+
cleanupName = parts[2]
260+
}
261+
// Assume the first service config for a module is sufficient to
262+
// determine the cleanup name.
263+
break
264+
}
265+
}
266+
241267
modulePathFragment := "/" + moduleName + "/"
268+
cleanupPathFragment := "/" + cleanupName + "/"
242269
lines := strings.Split(string(fileBytes), "\n")
243270
var newLines []string
244271
for i := 0; i < len(lines); i++ {
245272
line := lines[i]
246273
if strings.Contains(line, "source:") {
247274
// It's a source line, check it for the module name.
248-
if strings.Contains(line, modulePathFragment) {
275+
if strings.Contains(line, modulePathFragment) || strings.Contains(line, cleanupPathFragment) {
249276
if i+1 < len(lines) {
250277
i++ // Remove both source and dest lines.
251278
}
252279
continue
253280
}
254281
}
255-
if strings.Contains(line, modulePathFragment) {
282+
if strings.Contains(line, modulePathFragment) || strings.Contains(line, cleanupPathFragment) {
256283
// Remove any non-source line containing the module name.
257284
continue
258285
}

internal/stategen/cleanup_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func TestCleanupLegacyConfigs(t *testing.T) {
3030
"ai",
3131
// Test an individually-released module in release-please-config-individual.json, etc.
3232
"auth",
33+
"cloudtasks",
3334
}
3435
for _, testModuleName := range testModuleNames {
3536
// Create a temporary directory for the test repo.

0 commit comments

Comments
 (0)