Skip to content

Commit

Permalink
add support for glob pattern to the prautomation->deletes->files (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
floreks authored Dec 18, 2024
1 parent 402cd15 commit 5883324
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/pr/deletes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func applyDeletes(deletes *DeleteSpec, ctx map[string]interface{}) error {
dest = []byte(f)
}

if err := os.Remove(string(dest)); err != nil {
if err := removeMatches(string(dest)); err != nil {
return err
}
}
Expand Down
15 changes: 15 additions & 0 deletions pkg/pr/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,18 @@ func replaceTo(from, to string, rep func(data []byte) ([]byte, error)) error {
func replaceInPlace(path string, rep func(data []byte) ([]byte, error)) error {
return replaceTo(path, path, rep)
}

func removeMatches(glob string) error {
matches, err := filepath.Glob(glob)
if err != nil {
return err
}

for _, match := range matches {
if err := os.Remove(match); err != nil {
return err
}
}

return nil
}

0 comments on commit 5883324

Please sign in to comment.