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
Feature Request: Predicate to skip rule if a file was changed #754
Comments
Thanks for the proposal. Could you share a bit more about the approval conditions for each of your rules and how they combine as part of the overall policy? What is the overall behavior you are trying to achieve? I've found that you can sometimes avoid the need for negative/exclude conditions with the right combination of rules, but you need to know the high-level goal to design such a policy. |
We have a process that happens in two steps: Step 1A PR is created and it :
We'd like to apply a policy which requires an approval from some user in group A. Step 2A PR is created and it:
We'd like to apply a policy which requires an approval from some user in group B. From what I can tell - there's no way to segregate these rules in a simple way. I've explained the only solution I've been able to come up with (above). Unfortunately it's convoluted and requires updating if there's new directories which could be modified as part of step 1. We'd like to apply these rules solely based off file changes, as most other things with the PRs are far too dynamic (naming, author, line count) etc. If you have another way which accomplishes this, then I'd be glad to use that, although the exclusion logic makes this case very easy to solve. |
Another solution which doesn't overload ie. In Step 1 (above) we could limit the filtering to |
I thought about this a bit and have a suggestion using existing features that may work: policy:
approval:
- group B approved archive files
- or:
- group A approved foo files
- pull request only archives files
approval_rules:
- name: group B approved archive files
if:
changed_files:
paths:
- '^foo/archive/.*$'
requires:
count: 1
team: ["org/group-b"]
- name: group A approved foo files
if:
changed_files:
paths:
- '^foo/[^/]+\.json$'
requires:
count: 1
team: ["org/group-a"]
- name: pull request only archives files
if:
only_changed_files:
paths:
- '^foo/[^/]+\.json$'
- '^foo/archive/.*$'
requires:
conditions:
changed_files:
paths:
- '^foo/archive/.*$' The idea is that groups A and B have to approve any PRs that change the paths they care about (the rules are skipped if the PRs only change other files.) Then, the This uses the new required conditions feature from #752, which is in the I'll also admit it's non-obvious and that a new predicate would probably make it easier to write policies like this. If that doesn't work and you do want to add a new predicate, I think either of:
will work better than adding Of those, my guess is that |
Thank you! I will try this out and get back to you 😄 |
I appreciate the help with the rules you've setup, they accomplish the goals, thank you for taking the time with that! As you've called out - it's non-obvious, and we'd like the rules to be simpler so they can be more easily maintained by other teams. So I've opened a new PR #756, implementing |
Situation
We are running into limitations with policy bot and would like a new feature.
Given 2 PRs which should each trigger a rule specific to them
foo/archive/
are touchedfoo/bar.json -> foo/archive/bar.json
In this exact scenario, there's no way simple way to create a rule which would apply two rules separately. This is because there's no way to negate/exclude certain paths explicitly. If go supported negative look-ahead regex statements, this would not be a problem.
Current Rule Predicates (Convoluted)
Proposed Feature
Have a
excludePaths
feature for thechanged_files
predicate.Behaviour:
changed_files
is satisfied if:excludePaths
listpaths
andexcludePaths
rulesSolution
Having a functionality similar to the proposed
excludePaths
inchanged_files
would solve the above scenario we are facing because we could negate files explicitly, rather than having to try and negate files by creating an exhaustive list withonly_changed_files
.paths: "^foo/a-zA-Z0-9_.-+$"
andexcludePaths: "^foo/archive/.*
I already have some local changes which I believe implement this functionality. Figured I'd open an issue and see if there's any alternatives suggested for negating files
before I PR this.The text was updated successfully, but these errors were encountered: