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

Support for exclusion paths #9

Closed
jalaziz opened this issue Aug 21, 2019 · 6 comments · Fixed by #22
Closed

Support for exclusion paths #9

jalaziz opened this issue Aug 21, 2019 · 6 comments · Fixed by #22
Labels
enhancement New feature or request

Comments

@jalaziz
Copy link
Contributor

jalaziz commented Aug 21, 2019

There are cases where we want to match an entire directory but not certain subdirectories.

Instead of having to list each matching subdirectory, it would be nice to be able to exclude some paths from a match.

An example may be:

label1:
- match: "example1/**/*"
  exclude: ["example1/foo/*", "example1/bar/*"]
@damccorm damccorm added the enhancement New feature or request label Aug 22, 2019
@damccorm
Copy link
Contributor

This seems like a helpful idea! I think we probably should be able to do something like this, I want to be careful here though - I don't want to break existing configurations, so I don't want to change the syntax of the yml file.

I think a better approach might be to support ! as a negate pattern. So you're example would look the following instead:

label1:
- "!example1/foo/*"
- "!example1/bar/*"
- "example1/**/*"

Probably, we'd want to evaluate sequentially until we find a pattern that matches. So that way we could even do something like:

label2:
- "!example2/foo/bar"
- "example2/foo/**/*"
- "!example2/**/*"
- "**/*"

The above example would not match example2/foo/bar/abc.txt, would match example2/foo/baz/abc.txt, would not match example2/notFoo/baz/abc.txt, and would match notExample2/foo/baz/abc.txt since the patterns are evaluated in order - I think this would be about as powerful as we can get.

Thoughts?

@jalaziz
Copy link
Contributor Author

jalaziz commented Aug 22, 2019

I don't want to break existing configurations, so I don't want to change the syntax of the yml file.

Actually, that's exactly why I proposed the syntax above. Maps aren't currently handled and it should be possible to support existing configuration files without breaking them.

I had thought about negation, but my fear is that it would cause confusion with the semantics of the list as it stands today. Today the label is applied if any path matches. Should negation mean that a non-match should receive the label? Or that we should stop searching? It would also mean that the order of the rules matter. That's why I figured it would be better to be explicit with a map.

That being said, if you're comfortable with order being significant, then I'd certainly prefer your proposed syntax. It's certainly simpler than what I proposed!

@damccorm
Copy link
Contributor

Actually, that's exactly why I proposed the syntax above. Maps aren't currently handled and it should be possible to support existing configuration files without breaking them.

Ah I see, that makes sense - at the same time, I don't think I want us to support 2 different syntaxes if possible though - that leads me to prefer an additive pattern if possible

if you're comfortable with order being significant

I actually think this is a pretty common pattern that I've seen elsewhere. I think as long as we doc it, it should be fine. I think it makes intuitive sense as well (at least to me 😄).

jalaziz added a commit to jalaziz/labeler that referenced this issue Sep 14, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
jalaziz added a commit to jalaziz/labeler that referenced this issue Sep 14, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
jalaziz added a commit to jalaziz/labeler that referenced this issue Sep 14, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
jalaziz added a commit to jalaziz/labeler that referenced this issue Sep 14, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
jalaziz added a commit to jalaziz/labeler that referenced this issue Sep 14, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
@jalaziz
Copy link
Contributor Author

jalaziz commented Sep 14, 2019

@damccorm took a stab at this. Testing against a local repo has proven to provide the flexibility we need.

jalaziz added a commit to jalaziz/labeler that referenced this issue Oct 3, 2019
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
@fluzzi
Copy link

fluzzi commented Feb 14, 2020

i'm trying to use this to match only if specific file is changed, but not if that specific file and another one are modified but dosn't seem possible with this change.

the idea would be to add the label only if all the files match the pattern, is that possible?

@jalaziz
Copy link
Contributor Author

jalaziz commented Apr 26, 2020

i'm trying to use this to match only if specific file is changed, but not if that specific file and another one are modified but dosn't seem possible with this change.

the idea would be to add the label only if all the files match the pattern, is that possible?

@fluzzi discussion is taking place in #22. However, I think I can support your use case if the maintainers are willing to accept my map configuration proposal.

Your use case could be represented as:

label1:
- match: "example1/foo"
  exclude: ["example1/bar"]

jalaziz added a commit to jalaziz/labeler that referenced this issue May 2, 2020
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
jalaziz added a commit to jalaziz/labeler that referenced this issue May 27, 2020
Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes actions#9
@dakale dakale closed this as completed in #22 Jun 1, 2020
dakale pushed a commit that referenced this issue Jun 1, 2020
* Add support for exclusions

Paths can be negated to stop searching through the remaining patterns in
a the glob list. All changed files tested and at least one matching file
will result in a label being added.

Fixes #9

* Add support for "AND"-ed matches

A new "rich" matcher object can be provided instead of a normal glob.

The matcher object has two fields that accept an array of globs:
* Globs in "all" must all match every changed file.
* Globs in "some" must all match at least one changed file.

Combined with negated globs, this allows for a precise control of when
labels are applied.

* Rename `some` to `any`

* Update README
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants