@@ -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 }
0 commit comments