palantir / policy-bot

A GitHub App that enforces approval policies on pull requests
Apache License 2.0
771 stars 104 forks source link

Support glob filename patterns #853

Open reegnz opened 1 month ago

reegnz commented 1 month ago

When working with files, policy-bot should be providing basic glob support.

When working with common unix tools, glob-support tends to be either built-in, or augmented by the wrapping shell evaluating globs. It's not that common using regex to match filename patterns.

Using filename pattern matching is arguable also more secure than raw regex.

Please support either globs or gitignore patterns (which also resemble globs).

Seems like go has glob functionality already built into it's standard library, and is much more performant in matching filenames than regex: https://github.com/golang/go/blob/master/src/path/filepath/match.go#L44

I imagine config could look like this:

changed_files:
  glob: true
  paths:
  - **/*.yaml
  - **/some/**/pattern/*.py
asvoboda commented 1 month ago

Golang's default glob doesn't actually support **: https://github.com/golang/go/issues/11862. To support this, we'd likely need to use github.com/bmatcuk/doublestar.

I think we'd be open to a potential contribution here if you'd like, but internally regexes work quite well for us.

reegnz commented 1 month ago

I'll see if I can make that change and send a PR for it.