Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for glob pattern to the prautomation->deletes->files #586

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this still work for non-glob patterns?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, if full filepath is provided, filepath.Glob checks for file existence and returns it as part of matches array if it exists, otherwise it returns null and nothing happens.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool that works then

if err != nil {
return err
}

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

return nil
}
Loading